golang-safety

Apply defensive Go patterns to prevent panics and data corruption.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Go projects frequently suffer from nil panics, silent data corruption, and subtle runtime bugs caused by nil interfaces, nil maps, and unsafe conversions. This Skill captures defensive patterns to prevent panics and correctness issues across typical Go code.

Core Features & Use Cases

  • Nil safety patterns for interfaces and pointers to avoid typed nil traps.
  • Defensive copying for exported getters, immutable internal state, and safe initialization.
  • Safe resource handling: defer in loops, proper initialization of maps, and zero-value safe APIs.
  • Floating-point epsilon comparisons and guard against division by zero in numeric code.
  • Cross-cutting guidance for concurrency, slice/map safety, and initialization.

Quick Start

Apply the nil-safety patterns to your Go codebase by reviewing the examples and implementing defensive checks and safe copies.

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 panics in Go when using interfaces and pointers?

Prevent nil panics in Go by applying typed nil checks and defensive patterns for interface and pointer handling. This approach mitigates subtle runtime bugs caused by nil interfaces and unsafe pointer conversions in backend services.

What is the best way to safely handle maps and slices in Go to avoid silent data corruption?

Handle maps and slices safely by ensuring proper map initialization and using zero-value safe APIs. Defensive copying for exported getters and immutable internal state prevents silent data corruption across Go projects.

How do I safely compare floating-point numbers and prevent division by zero in Go?

Safely compare floating-point numbers in Go by using epsilon comparisons instead of direct equality checks. Additionally, guard against division by zero to prevent panics and ensure numeric code robustness.

Why does a typed nil interface still cause a panic in Go?

A typed nil interface causes a panic in Go because the interface value itself is non-nil even when its underlying pointer is nil. Applying typed nil checks before invocation prevents these subtle runtime bugs.

How do I manage resource lifecycles safely with defer in Go loops?

Manage resource lifecycles safely by handling defer correctly within loops and ensuring robust initialization. This prevents resource leaks and maintains safe execution across concurrent Go services.