Go Best Practices
以下摘录自该仓库的 README(片段) · 在 GitHub 读完整 README →
Modern Go patterns — error handling, concurrency, structured logging with slog, and Go 1.22+
features agents miss.
Install
Cursor IDE
Claude Code
Skills only (any agent)
Or copy skills/ into your .cursor/skills/ or .claude/skills/ directory.
What's Included
Skills
- **go-best-practices** - Modern Go patterns — error handling, concurrency, structured logging with
slog, and Go 1.22+ features agents miss
Rules
- **best-practices** - Always-on rules that enforce current Go patterns
Commands
- /audit - Scan your codebase for Go anti-patterns
Why This Plugin?
AI agents are trained on data that includes outdated Go patterns. This plugin ensures your agent
uses current best practices:
- **Pre-1.22 Go** — Agents generate C-style for loops and unnecessary loop variable shadow copies.
Go 1.22+ has range over int and fixed capture.
- **log.Printf instead of slog** — Structured logging with slog has been standard since Go 1.21.
Agents still use the legacy log package.
- **Bare error propagation** — Agents return err without wrapping. Errors need context at each
level for debugging.
- **Goroutine leaks** — Agents spawn goroutines without exit paths. Leaked goroutines consume memory
indefinitely.
- **Wrong error checks** — Agents use == or type assertion. Wrapped errors require errors.Is and
errors.As.
License
MIT