265866/claude-config/go-best-practices

Claude Code and agent skill by 265866/claude-config

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Go best practices. Use when reading or editing any .go file.

Install

npx vskill@latest install 265866/claude-config/go-best-practices

SKILL.md

The same SKILL.md was published earlier as 265866/claude-config/go-best-practices.

Go best practices

Apply Type System Discipline first.

Check the go directive in go.mod before applying version-gated APIs: slices, maps, cmp, and log/slog need Go 1.21, and errors.Join needs 1.20. Many of their functions are newer (slices.Concat and cmp.Or need 1.22; maps.Keys, maps.Values, maps.All, maps.Collect, slices.Sorted, slices.Collect, and slices.Values need 1.23), so check each function's added-in version against the directive. On an older floor, use golang.org/x/exp/slices or golang.org/x/exp/maps only when the module already depends on them; otherwise write the small helper. For log/slog below 1.21, keep the module's existing logger.

RuleSummary
Illegal states unrepresentableUnexported fields plus a validating constructor when invariants exist; small defined types over raw strings and ints. Validate once at creation.
EnumsDefined type + iota constants, zero value reserved for invalid unless zero is a real default. switch isn't exhaustive; make default arms fail loudly.
Consumer-side interfacesAccept interfaces, return concrete types. Define the interface in the package that uses it, sized to what that consumer calls. No producer-side interfaces "for mocking".
Error wrapping%w keeps the chain for errors.Is/As; %v severs it at trust boundaries. Terse lowercase context, no "failed to" cascades. Sentinel ErrX for identity, typed XError for data. Never return a typed nil as error.
Useful zero valuesMake the zero value ready to use: var mu sync.Mutex, var buf bytes.Buffer, lazy map init inside methods. Never copy a struct holding a mutex. No constructor ceremony when the zero value works.
Goroutine lifetimesEvery goroutine has a known exit and someone who waits. errgroup.WithContext + SetLimit for fan-out; no fire-and-forget. In modules declaring go 1.22+, loop vars are per-iteration: no x := x copies.
Channel ownershipThe writing goroutine creates and closes the channel; receivers range and cancel or drain if they stop early. Return <-chan T to encode ownership. Unbuffered or size 1 unless measured otherwise.
Context disciplinectx context.Context is the first parameter, never a struct field. defer cancel() on every derived context. Values carry request-scoped cross-cutting data (trace id, principal), never ordinary parameters.
Generics restraintType parameters only when identical bodies differ only by type. If the body just calls methods, use an interface. Check slices, maps, cmp before writing your own.
AliasingSlices are headers over shared memory; maps are pointers to it. Clone at ownership boundaries; append on a subslice can overwrite the parent.
Options ladderPlain args, then a config struct, then functional options. Escalate to a config struct for several optional knobs with usable defaults; to functional options only when most callers pass none and the list is long or growing, or when an option can fail.
defer cleanupdefer the release immediately after a successful acquire. Writers capture the Close error (writeback failures surface there); read-only closes discard it explicitly.
slogStructured key-value logging via slog; *Context variants so handlers see trace ids; slog.With for repeated attrs; LogAttrs on hot paths.
Package layoutPackages named by what they provide, read at the call site. No util/common/helpers. internal/ for non-public code. No stutter (store.Client, not store.StoreClient).
Table-driven testsSlice of named cases + t.Run subtests. t.Helper() in assertion helpers, t.Cleanup (not defer) in setup helpers.
Narrow suppressionsNever add _ = err or //nolint to silence a real problem. For a genuine false positive, use //nolint:<linter> with a one-line justification.

Examples: references/patterns.md.

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

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
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/265866/claude-config/go-best-practices/badge)](https://verified-skill.com/skills/265866/claude-config/go-best-practices)

Something wrong with this skill or its page? Tell us.