Effective Go
Apply best practices and conventions from the official Effective Go guide to write clean, idiomatic Go code.
When to Apply
Use this skill automatically when:
- Writing new Go code
- Reviewing Go code
- Refactoring existing Go implementations
Core Concepts
| Topic | Description | Reference |
|---|---|---|
| Formatting | Always use gofmt - this is non-negotiable | core-formatting |
| Naming | MixedCaps for exported, mixedCaps for unexported | core-naming |
| Error Handling | Check errors, return them, don't panic | core-error-handling |
| Concurrency | Share memory by communicating (use channels) | core-concurrency |
| Interfaces | Keep small (1-3 methods ideal); accept interfaces, return concrete types | core-interfaces |
| Documentation | Document all exported symbols | core-documentation |
Key Reminders
Follow the conventions and patterns documented at https://go.dev/doc/effective_go:
- Formatting: Use
gofmt- this is non-negotiable - Naming: No underscores, use MixedCaps for exported names
- Error handling: Always check errors; return them, don't panic
- Concurrency: Share memory by communicating
- Interfaces: Keep small and accept interfaces, return structs
- Documentation: Document all exported symbols
References
- Official Guide: https://go.dev/doc/effective_go
- Code Review Comments: https://github.com/golang/go/wiki/CodeReviewComments
- Standard Library: Use as reference for idiomatic patterns