Skip to content
Back to skills

Go Idioms

ASecurity

Apply idiomatic Go for error handling, context propagation, and interface design

  • 3 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 3, 2026
ai-agentsgorefactoringapi

Works with

  • api

Security analysis

A100/100

Scanned September 3, 2026

npx -y skills add black141312/ada --skill go-idioms --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Go Idioms?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Go Idioms
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/black141312-go-idioms/badge)](https://www.skillsdirectory.com/skills/black141312-go-idioms)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: go-idioms
description: Apply idiomatic Go for error handling, context propagation, and interface design
category: languages
---

# Go Idioms

Use this when reviewing or refactoring Go that fights the language — swallowed errors, missing context, or fat interfaces.

1. Handle every error explicitly at the call site: return it wrapped with `fmt.Errorf("doing X: %w", err)` so callers can `errors.Is`/`errors.As` it; never discard with `_` unless intentional and commented.
2. Thread `context.Context` as the first parameter through any call that does I/O or can block, and honor cancellation (`ctx.Err()`, `<-ctx.Done()`).
3. Define interfaces where they're consumed, keep them small (one or two methods), and accept interfaces but return concrete types.
4. Use `defer` for cleanup (close, unlock) right after acquiring the resource; prefer `sync.Mutex` zero-value over pointers and don't copy locks.
5. Replace sentinel-error string matching with typed errors or `errors.Is`, and use `errors.Join` to aggregate when needed.
6. Run `go vet`, `gofmt`/`goimports`, and `staticcheck`; fix shadowed `err`, unchecked returns, and ineffective assignments.

## Rules
- Wrap errors with `%w` (not `%v`) when callers may need to inspect the cause; add context, don't just rethrow.
- Don't start goroutines you can't stop — every goroutine needs a clear exit path tied to a context or channel close.
- Avoid `interface{}`/`any` in APIs; use concrete types or generics. Empty interfaces push type errors to runtime.
- Name things tersely and idiomatically (`r io.Reader`, not `reader`), and return early instead of nesting `if/else`.
- Don't panic across package boundaries — return errors; reserve `panic` for truly unrecoverable programmer bugs.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…