golang-safety

Enforce defensive Go coding patterns for nil handling, slice safety, and resource lifecycles.

1|Updated May 26, 2026
One-click install
npx skills add https://github.com/tokiou/caba-inseguridad-v2-be --skill golang-safety-tokiou
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-safety
Source: https://github.com/tokiou/caba-inseguridad-v2-be/tree/main/.claude/skills/golang-safety
Command: npx skills add https://github.com/tokiou/caba-inseguridad-v2-be --skill golang-safety-tokiou

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Golang-safety helps you avoid crashes and subtle data corruption caused by unsafe Go assumptions—like nil interfaces/maps, slice/map aliasing, risky numeric conversions, and incorrect resource lifecycles.

Core Features & Use Cases

  • Nil-safety and typed-nil correctness: Prevents nil interface traps and nil pointer receiver/function panics by enforcing explicit nil handling patterns.
  • Slice & map safety: Stops append aliasing bugs and ensures defensive copies for exported getters to protect internal state.
  • Numeric & floating-point correctness: Avoids silent truncation in integer narrowing and incorrect float equality by using bounds checks and epsilon comparisons.
  • Resource lifecycle correctness: Prevents defer-in-loop accumulation issues so files, DB connections, and HTTP bodies close per-iteration.

Quick Start

Use the golang-safety skill to review your Go code for nil safety, defensive copying, numeric narrowing overflow, and defer-in-loop resource leaks.

Frequently Asked Questions about golang-safety

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent nil interface panics in Go code?

To prevent nil interface panics in Go, enforce explicit nil handling patterns that validate nil interface, function, and value behavior before usage, avoiding typed-nil traps where a non-nil interface wrapping a nil pointer causes a runtime crash.

What is the best way to stop slice aliasing bugs when appending in Go?

To stop slice aliasing bugs when appending in Go, apply defensive copying and cloning patterns to prevent shared backing array mutations, ensuring exported getters return copies to protect internal state from silent data corruption.

How do I avoid silent truncation during numeric narrowing conversions in Go?

To avoid silent truncation during numeric narrowing conversions in Go, add explicit bounds checks before converting between integer types and use epsilon comparisons for floating-point equality to prevent silent correctness failures.

Why does using defer inside a Go loop cause resource leaks?

Using defer inside a Go loop causes resource leaks because deferred functions only execute when the enclosing function returns, leading to per-iteration resource accumulation where files, DB connections, and HTTP bodies remain open until the loop finishes.

Can I use defensive coding patterns to secure Go concurrency boundaries and callbacks?

Yes, defensive coding patterns secure Go concurrency boundaries and callbacks by validating nil function values, structuring defer usage correctly, and implementing safe helpers that prevent panics across goroutine borders and protocol encoding/decoding tasks.