golang-safety

Enforce defensive Go coding patterns to prevent panics and silent data corruption.

1|Updated Mar 21, 2026
One-click install
npx skills add https://github.com/dashkan/pivox --skill golang-safety-dashkan
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-safety
Source: https://github.com/dashkan/pivox/tree/main/.agents/skills/golang-safety
Command: npx skills add https://github.com/dashkan/pivox --skill golang-safety-dashkan

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

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.

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 and typed nil traps in Go?

Prevent nil interface panics in Go by applying defensive nil checks for interfaces, pointers, maps, slices, and funcs to stop typed-nil traps and runtime panics from nil map writes or nil function calls.

Why does my Go slice data get corrupted after using append?

Slice data corruption in Go happens due to append aliasing and subslice backing-array retention. Avoid this by applying defensive copying patterns for exported collection getters to prevent silent data modification.

What is the best way to compare floating-point numbers for equality in Go?

The best way to compare floating-point numbers in Go is using epsilon comparisons for float equality and reconciliation logic, which prevents silent precision errors that direct equality checks cause.

How do I fix resource leaks caused by defer in Go loops?

Fix defer-in-loop resource leaks in Go by ensuring proper cleanup executes per iteration rather than deferring until function return, which prevents goroutine lifecycle issues and resource exhaustion.

How to stop integer overflow and truncation when doing numeric conversions in Go?

Stop integer overflow and truncation in Go numeric conversions by enforcing bounds checks for narrowing conversions, ensuring values fit within target type limits before casting to prevent silent data corruption.