What problem does it solve?
Defensive Golang coding eliminates common correctness failures in normal Go programs that otherwise lead to panics, subtle runtime bugs, and silent data corruption.
Core Features & Use Cases
- Nil safety for interfaces, pointers, maps, slices, and funcs: prevent typed-nil traps and runtime panics from nil map/slice writes or nil function calls.
- Slice and map integrity: avoid append aliasing, subslice backing-array retention, and unsafe concurrent map access patterns.
- Numeric and floating-point correctness: stop silent truncation/overflow in integer conversions and use epsilon comparisons for float equality and reconciliation logic.
- Resource and lifecycle safety: prevent defer-in-loop and goroutine lifecycle issues; ensure proper cleanup per iteration.
- Defensive copying and deterministic outputs: return defensive copies for exported collection getters and sort map keys when stable output matters.
Quick Start
Use the golang-safety skill when reviewing a Go function that could panic or corrupt data, and ask it to produce a safer rewrite with nil checks, defensive copies, and overflow/bounds validation where applicable.