alex123098/my-dotfiles/go-safety
Claude Code and agent skill by alex123098/my-dotfiles
Trust tier 3
- community
Source check pending
Checking that the SKILL.md file is still in the repository.
Defensive Go coding — prevent nil panics, slice aliasing, race conditions, numeric overflow, and resource leaks. Use when reviewing Go code for correctness or writing code that must be robust against common Go pitfalls.
Install
npx vskill@latest install alex123098/my-dotfiles/go-safetySKILL.md
Procedure
- Nil Safety: The typed nil interface trap — returning a typed nil pointer from an interface function creates
interface{type: *T, value: nil}which is NOT== nil. Always return untypednilfor the nil case:return nil, notreturn var h *T. Writing to a nil map panics — always initialize withmake()or lazy-init in methods. Indexing a nil slice panics. Ranging over nil map/slice/channel is safe (0 iterations). Use safe type assertions:v, ok := x.(T)— never barex.(T). - Slice & Map Aliasing:
appendreuses the backing array if capacity allows — both slices then share memory and silently corrupt each other. To force a copy on append:s[:len(s):len(s)](full slice expression). Return defensive copies from exported functions:return slices.Clone(c.hosts)instead ofreturn c.hosts. Never return internal slice/map references — callers can mutate your internals. - Numeric Safety: Integer conversions truncate silently —
int64(3_000_000_000)cast toint32wraps to-1294967296. Always check bounds againstmath.MaxInt32/math.MinInt32before converting. Integer division by zero panics — always guard. Float comparison with==is unreliable — usemath.Abs(a-b) < epsilon. - Resource Safety:
deferruns at function exit, not loop iteration. Extract loop body withdeferto a separate function, or resources accumulate until return. Alwaysdefer rows.Close()immediately afterdb.QueryContext(). Useos.Root(Go 1.24+) for user-supplied file paths to prevent traversal. - Zero-Value Design: Design types so
var x MyTypeis safe and usable. Nil map fields in structs panic on first write — use lazy init withsync.Once.sync.Mutexandbytes.Bufferare safe at zero value. Enum iota should start at 1 or use an Unknown sentinel at 0 — var zero value silently becomes the first enum member. - Concurrent Safety: Maps MUST NOT be accessed concurrently without synchronization — concurrent write+read causes a hard crash. Use
sync.Mapfor read-heavy patterns,sync.Mutex+map for write-heavy. Use-racealways in CI. Usego.uber.org/goleakto detect goroutine leaks.
Pitfalls
- Bare type assertion
x.(T)panics on type mismatch — always use comma-ok form. - Writing to a nil map panics — never
var m map[K]V; m[k] = v. - Comparing
err == io.EOFinstead oferrors.Is(err, io.EOF)— fails if err is wrapped. - Returning internal slice reference — callers can mutate your backing array.
- Using
anywhen generics will do — loses compile-time type safety. - Defer inside a loop — defers accumulate until function returns, not per iteration.
- Assuming
appendalways allocates — it reuses backing array silently when capacity permits.
Verification
go vet ./...catches nil pointer derefs, unreachable code.- No bare type assertions (
x.(T)) in the codebase — all use comma-ok form. - All exported functions returning slices use
slices.Cloneor full-slice expressions. - No
deferinside loops — extracted to helper functions. go test -race ./...passes.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingpi/.pi/agent/skills/go-safety/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/alex123098/my-dotfiles/go-safety)