go-best-practiceslisted
Install: claude install-skill lklimek/claudius
# Go Best Practices
## Technical Standards
- **Go Version**: 1.21+ (or latest stable)
- **Code Style**: gofmt/goimports enforced
- **Linting**: golangci-lint with comprehensive checks
- **Testing**: go test with table-driven tests
- **Documentation**: One-line Godoc comment for every exported identifier; expand only when non-obvious
- **Error Handling**: Explicit with error wrapping (fmt.Errorf with %w)
- **Modules**: Go modules for dependency management
- **Context**: context.Context for cancellation and timeouts
## Best Practices
- Accept interfaces, return structs
- Keep interfaces small (single-method often best)
- Use context.Context for cancellation propagation
- Always check errors — don't ignore with `_`
- Use defer for cleanup (close files, unlock mutexes)
- Goroutines: always know when they exit
- Channels for communication, mutexes for state
- Prefer composition over embedding
- Use `internal/` package for private code
- Prefer standard library first
## Common Patterns
- **Error Wrapping**: `fmt.Errorf("context: %w", err)`
- **Options Pattern**: Functional options for constructors
- **Context**: Pass as first parameter
- **Interfaces**: io.Reader, io.Writer, io.Closer patterns
- **Middleware**: Handler wrapping for HTTP servers
- **Worker Pools**: Channel-based task distribution
- **Graceful Shutdown**: Signal handling with context cancellation
## Concurrency
- Always handle goroutine lifecycle — know when they exit
- Use context for cancellation propagation
-