go-best-practices

v2026.09.24

Production Go patterns — lifecycle, concurrency, config, testing, CI. Use when writing, reviewing, or refactoring Go code. Triggers on Go code review, Go refactoring, or 'go best practices'.

GitHub
安装命令
npx skhub add poteto/go-best-practices
Markdown
SKILL.md

Go Best Practices

PatternWhen to apply
Minimal mainNew binaries
Single bootstrapApp wiring across modes
Ordered shutdownLong-running processes
Non-blocking fanoutChannel-based event systems
Concurrency testingAny goroutine code
Layered configMulti-source configuration
Cross-platform pathsFile/config path resolution
Secure debug loggingHTTP client instrumentation
Golden test matricesRendering / output components
Focused lintersCI pipeline setup

Read references/patterns.md for code examples.

Rules

  1. main.go is a stub. Call cmd.Execute() and nothing else. Gate diagnostics (pprof) behind env vars.

  2. One bootstrap path. All modes (interactive, headless, test) share the same initialization function. Two paths will drift.

  3. Ordered shutdown. Cancel dependents before their dependencies, then run independent cleanup in parallel under a timeout context. WaitGroup the parallel phase.

  4. Never block the sender. Non-blocking channel sends with an explicit drop policy. Log drops at debug level. Document the policy.

  5. Test concurrency mechanically. testing/synctest for deterministic timing, goleak.VerifyNone for leak detection, dedicated regression tests for timer/channel deadlocks.

  6. Explicit config precedence. Global → project → flags. Walk up from CWD to discover project configs, reverse so closest wins, deep-merge.

  7. Centralize platform paths. One function per concern. Resolution order: env override → XDG → platform default → fallback.

  8. Redact secrets in debug logs. Wrap http.RoundTripper. Filter headers matching authorization, api-key, token, secret. Gate on debug level to skip allocation in prod.

  9. Golden tests over matrices. Cross dimensions (layout × theme × size) as parallel subtests. Sweep continuous ranges to catch off-by-one bugs.

  10. Focused linters, not all linters. Enable what catches real bugs (bodyclose, noctx, tparallel). Disable noisy defaults. Add project-specific checks as scripts. Always -race in tests.

发现
标签

此技能尚未发布标签。

版本
最新版本元数据

版本

v2026.09.24

发布时间

2026年9月24日

分类

未分类

许可证

MIT

源路径

.agents/skills/go-best-practices

默认分支

main

最新提交

82d2921

Tree SHA

9fccb6b