golang-safety

Apply defensive safety checks to Go code for nil handling, aliasing, and numeric correctness.

Updated May 28, 2026
One-click install
npx skills add https://github.com/vanstinator/semantic-search --skill golang-safety-vanstinator
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-safety
Source: https://github.com/vanstinator/semantic-search/tree/main/.agents/skills/golang-safety
Command: npx skills add https://github.com/vanstinator/semantic-search --skill golang-safety-vanstinator

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill prevents common defensive Go mistakes that lead to panics and subtle correctness failures by enforcing safe patterns around nil handling, slices/maps, numeric conversions, floating-point comparisons, and resource lifecycles.

Core Features & Use Cases

  • Nil-safety for interfaces, errors, functions, and receivers: avoid typed-nil traps, nil func calls, and nil pointer receiver dereferences.
  • Slice and map safety: prevent nil map writes, concurrent map access issues, append aliasing/caller slice corruption, and subslice backing-array retention.
  • Numeric and float correctness: stop silent truncation during integer narrowing and use epsilon-based comparisons instead of float equality.
  • Resource and immutability hygiene: ensure per-iteration defer semantics, close response bodies promptly, and return defensive copies from getters.
  • Use cases: code review or agent-generated implementations for Go services, libraries, and integrations where correctness under edge cases matters (APIs, protocol packing, caching, parsing, and concurrent components).

Quick Start

Ask an AI agent to review the following Go function for nil-safety, slice/map aliasing risks, numeric conversion overflow, float comparison correctness, and proper defer/close behavior, then return concrete fixes with explanations.

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 handling interfaces and zero-value maps?

Prevent nil panics in Go by applying defensive checks for typed-nil interfaces, nil map writes, and nil function calls, using comma-ok assertions and lazy initialization for zero-value usability.

What causes slice aliasing and backing array retention in Go, and how do I fix it?

Slice aliasing and backing array retention in Go happen when append operations corrupt caller slices or subslices retain large backing arrays. Fix this by returning defensive copies from exported collection getters.

Why does my Go code truncate integers when converting numeric types?

Numeric narrowing in Go silently truncates integers during type conversions. Prevent this correctness issue by enforcing bounds checks before casts to ensure safe numeric conversions.

How do I properly compare floating-point values in Go without equality checks?

Comparing floating-point values in Go requires epsilon-based comparisons instead of direct float equality checks to avoid silent logic failures in edge cases.

How do I handle defer and resource lifecycle issues in Go HTTP handlers and concurrent components?

Handle defer and resource lifecycle issues in Go by using per-iteration defer helpers, closing HTTP response bodies promptly, and ensuring robust behavior in concurrent components.

Can I use this to review Go services and APIs for concurrent map access and protocol serialization safety?

Yes, you can review Go services, APIs, protocol serialization, parsers, and caches for concurrent map access issues and robust behavior under edge cases and zero values.