← Back to list

go-nil-pointer
by JamesPrial
WIP - collection of various Claude stuff i make/use/have_Claude_hallucinate
⭐ 2🍴 0📅 Jan 23, 2026
SKILL.md
name: go-nil-pointer description: Pointer receiver nil safety - methods can be called on nil
Pointer Receiver Nil
Problem
Methods with pointer receivers can be called on nil. Must handle nil receiver.
Pattern
WRONG - Assume receiver is non-nil
type Tree struct {
Value int
Left *Tree
}
func (t *Tree) Sum() int {
return t.Value + t.Left.Sum() // PANIC if t or t.Left is nil
}
CORRECT - Handle nil receiver
type Tree struct {
Value int
Left *Tree
Right *Tree
}
func (t *Tree) Sum() int {
if t == nil {
return 0 // Nil tree has sum of 0
}
return t.Value + t.Left.Sum() + t.Right.Sum()
}
// Now safe to call
var tree *Tree // nil
sum := tree.Sum() // Returns 0, no panic
Use Cases
Nil receiver pattern enables elegant recursive algorithms and optional behavior.
Quick Fix
- Check if receiver is nil at method start
- Define sensible zero behavior for nil receiver
- Document whether methods are nil-safe
When NOT to Use
If nil receiver doesn't make semantic sense, panic early with clear message.
Score
Total Score
65/100
Based on repository quality metrics
✓SKILL.md
SKILL.mdファイルが含まれている
+20
✓LICENSE
ライセンスが設定されている
+10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
✓最近の活動
1ヶ月以内に更新
+10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
✓タグ
1つ以上のタグが設定されている
+5
Reviews
💬
Reviews coming soon
