golang-safety

Review Go code for nil safety, slice aliasing, and numeric conversion bugs.

2|Updated Mar 13, 2023
One-click install
npx skills add https://github.com/haipham22/golang-sample --skill golang-safety-haipham22
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-safety
Source: https://github.com/haipham22/golang-sample/tree/main/.agents/skills/golang-safety
Command: npx skills add https://github.com/haipham22/golang-sample --skill golang-safety-haipham22

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you prevent common Go correctness bugs that lead to panics, hidden data corruption, and difficult runtime failures.

Core Features & Use Cases

  • Nil safety: Avoid typed nil traps, nil maps, nil function calls, and nil pointer receiver crashes.
  • Slice and map safety: Prevent append aliasing, subslice retention, and accidental mutation through shared collections.
  • Numeric and resource safety: Guard against silent conversion truncation, float comparison mistakes, and deferred cleanup inside loops.
  • Use case: Review a production Go service that is intermittently failing and harden its validation, copying, conversion, and cleanup logic before release.

Quick Start

Use the golang-safety skill to review the attached Go code for nil checks, defensive copying, and unsafe conversions.

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 pointer panics in Go production services?

Prevent nil panics in Go by applying nil-safe guards, zero-value-friendly initialization, and defensive checks against typed nil traps and nil function calls. This ensures production services avoid runtime crashes caused by uninitialized receivers, maps, or callbacks.

Why does my Go slice append operation cause hidden data corruption?

Slice append data corruption in Go occurs due to slice aliasing and subslice retention. Resolve this by creating defensive copies of slices before mutation, preventing accidental shared collection modifications during refactoring or API processing.

What is the best way to handle float comparison errors in Go?

The best way to handle float comparison errors in Go is to use epsilon comparisons instead of direct equality checks. This numeric safety practice guards against silent conversion truncation and ensures accurate floating-point validation.

How do I fix resource cleanup leaks inside Go loops?

Fix resource cleanup leaks in Go loops by enforcing per-iteration resource cleanup instead of deferred cleanup patterns. Deferring inside loops delays release until function exit, causing resource lifecycle bottlenecks and unsafe runtime behavior.

Can I use defensive coding to review intermittent Go runtime failures?

Yes, you can use defensive coding to review intermittent Go runtime failures by validating callback safety, checking bounds, and hardening conversion logic. This detects hidden data corruption and unsafe lifecycles before releasing production services.