Agent skill
go-nil-slice
Slice zero-value behavior - nil slice is usable
Install this agent skill to your Project
npx add-skill https://github.com/JamesPrial/claudefiles/tree/main/skills/golang/nil/slice
SKILL.md
Slice Zero-Value
Problem
Nil slices are valid and usable, but behavior differs from empty slices.
Pattern
CORRECT - Nil slice works with append
var s []int // nil slice
s = append(s, 1, 2, 3) // OK, creates new backing array
fmt.Println(s) // [1 2 3]
Nil vs Empty Slice
var nilSlice []int // nil slice
emptySlice := []int{} // empty slice (non-nil)
len(nilSlice) == 0 // true
len(emptySlice) == 0 // true
nilSlice == nil // true
emptySlice == nil // false
json.Marshal(nilSlice) // "null"
json.Marshal(emptySlice) // "[]"
When It Matters
// JSON encoding differs
type Response struct {
Items []string // Will encode as null if nil, [] if empty
}
Quick Fix
- Nil slices work with append, len, range
- Use nil for "no data", []T{} for "empty data"
- Check JSON encoding behavior if needed
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
plugin-packager
Package claudefiles components into a valid Claude Code plugin
plugin-packager-validation
Plugin validation errors and fixes
plugin-packager-subset
Package language-specific subsets of claudefiles
plugin-packager-hooks
Handle hook scripts and paths for plugin packaging
go-concurrency
Go concurrency patterns. Routes to specific patterns.
go-sync-primitives
sync.WaitGroup and sync.Mutex patterns
Didn't find tool you were looking for?