golang-safety

Identify nil-related panics and runtime bugs in Go code.

Updated Oct 1, 2024
One-click install
npx skills add https://github.com/mrlorentx/.files --skill golang-safety-mrlorentx
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-safety
Source: https://github.com/mrlorentx/.files/tree/main/ai/claude/skills/golang-safety
Command: npx skills add https://github.com/mrlorentx/.files --skill golang-safety-mrlorentx

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Defensive Go coding to prevent panics, silent data corruption, and subtle runtime bugs. Use whenever writing or reviewing Go code that involves nil-prone types (pointers, interfaces, maps, slices, channels), numeric conversions, resource lifecycle (defer in loops), or defensive copying. Also triggers on questions about nil panics, append aliasing, map concurrent access, float comparison, or zero-value design.

Core Features & Use Cases

  • Guidance on nil-safety and defensive copying across pointers, maps, slices, channels, and interfaces.
  • Best practices for safe type conversions, defer-in-loops handling, and zero-value design.
  • Use cases include code reviews, architecture reviews, and learning scenarios for robust Go safety.

Quick Start

Analyze the Go codebase to identify nil-safety gaps and apply defensive patterns to prevent panics and subtle bugs.

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 using pointers, maps, and slices?

Prevent nil panics in Go by enforcing defensive patterns like nil-safety checks and zero-value design before accessing pointers, maps, slices, channels, or interfaces. This ensures robust runtime safety during code execution.

What is the best way to handle defer in loops to avoid resource lifecycle bugs in Go?

The best way to handle defer in loops is applying safe defer usage patterns to prevent resource leaks and subtle runtime bugs. Defensive Go practices ensure resources are released correctly without causing lifecycle issues.

How do I stop silent data corruption from append aliasing and map concurrent access in Go?

Stop silent data corruption from append aliasing and map concurrent access by applying defensive copying and concurrency safety patterns. These practices prevent shared memory issues across Go routines.

Does this defensive Go approach work for code review and automated checks across existing projects?

Yes, defensive Go safety checks work for code review, architecture reviews, and automated checks across existing projects. It identifies nil-safety gaps and applies defensive patterns to prevent panics and subtle bugs.

Why does my Go code panic during robust type conversions and float comparisons?

Go code panics during type conversions and float comparisons when defensive coding patterns are missing. Applying best practices for safe type conversions and numeric handling prevents these subtle runtime bugs.