What problem does it solve?
It helps you write defensive Go code that avoids common crash paths (nil dereferences, nil map writes, nil function calls) and correctness failures that otherwise surface as subtle runtime bugs or silent data corruption.
Core Features & Use Cases
- Nil safety: prevents typed-nil interface traps, nil pointer receiver panics, nil function panics, and nil map write panics.
- Slice/map correctness: avoids append backing-array aliasing, subslice backing-array retention, unsafe concurrent map access patterns, and ensures deterministic results when iterating maps.
- Numeric & resource safety: catches silent truncation from integer narrowing, reduces float comparison pitfalls, and prevents
defer misuse inside loops that accumulates resources.
Use case: You are reviewing a Go pull request that sometimes panics in production and occasionally produces incorrect results—apply this to audit nil handling, slice/map ownership, numeric conversions, and lifecycle patterns like defer placement.
Quick Start
Use golang-safety to review the Go file you are working on and fix any nil-safety, slice/map aliasing, numeric conversion, float comparison, and defer-in-loop issues found.