golang-safety

Apply defensive Go patterns to prevent panics and runtime bugs.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go programs frequently suffer from panics and subtle runtime bugs due to nil interfaces, nil maps/slices, improper delegation, and unsafe type conversions. This Skill provides defensive patterns and checklists to prevent crashes and data corruption.

Core Features & Use Cases

  • Nil safety patterns: guards for nil receivers, typed nil interfaces, and nil function values.
  • Defensive copying: return safe copies of slices and maps to protect internal state.
  • Resource lifecycle safety: avoid defer-in-loops and ensure resources are released per iteration.
  • Initialization best practices: lazy and constructor-based initialization to prevent nil map panics.
  • Deterministic behavior: avoiding unintended aliasing and non-deterministic map iteration orders.

Quick Start

Apply these patterns by auditing representative Go code paths for nil interfaces, maps, and slices, refactoring to use defensive copies and proper initialization.

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 code?

Prevent nil panics in Go by applying defensive coding patterns like nil receiver guards, checking typed nil interfaces, and validating function values before invocation.

What's the best way to safely initialize maps and slices in Go?

Safely initialize maps and slices in Go using constructor-based or lazy initialization patterns to prevent nil map assignment panics and ensure deterministic behavior.

How do I avoid map and slice aliasing bugs in Go?

Avoid map and slice aliasing bugs in Go by implementing defensive copying patterns that return safe copies, protecting internal state from unintended modifications.

How do you handle unsafe numeric type conversions defensively in Go?

Handle numeric conversions defensively in Go by applying safe initialization checklists and guardrails to prevent subtle runtime bugs and data corruption.