go-nil
Go nil safety patterns. Routes to specific traps.
When & Why to Use This Skill
This Claude skill provides a comprehensive guide and pattern library for Go nil safety, specifically designed to help developers identify and avoid common runtime panics. It offers structured solutions for the most frequent 'nil traps' in Golang, including interface comparisons, map writes, and pointer dereferences, ensuring more robust and stable codebases.
Use Cases
- Identifying and fixing the 'typed nil != nil interface' logic error that causes unexpected behavior in conditional statements.
- Preventing runtime panics by implementing safe patterns for writing to maps and handling zero-value slices.
- Debugging 'nil pointer dereference' issues by applying best practices for pointer receivers and pre-dereference checks.
- Reviewing Go source code to detect uninitialized variables that could lead to system crashes in production.
| name | go-nil |
|---|---|
| description | Go nil safety patterns. Routes to specific traps. |
Nil Safety
Route by Type
- Interface nil trap → see interface/
- Map nil writes → see map/
- Slice zero-value → see slice/
- Pointer receivers → see pointer/
Quick Check
- Check pointers before deref
- Check maps before write
- Typed nil != nil interface
Common Gotcha
var p *int
if p == nil { // true
fmt.Println("nil pointer")
}