Go Patterns
This skill provides comprehensive Go patterns extending common design principles with Go-specific idioms.
Functional Options
Use the functional options pattern for flexible constructor configuration:
Benefits:
- Backward compatible API evolution
- Optional parameters with defaults
- Self-documenting configuration
Small Interfaces
Define interfaces where they are used, not where they are implemented.
Principle: Accept interfaces, return structs
Benefits:
- Easier testing and mocking
- Loose coupling
- Clear dependencies
Dependency Injection
Use constructor functions to inject dependencies:
Pattern:
- Constructor functions (New* prefix)
- Explicit dependencies as parameters
- Return concrete types
- Validate dependencies in constructor
Concurrency Patterns
Worker Pool
Context Propagation
Always pass context as first parameter:
Error Handling
Error Wrapping
Custom Errors
Sentinel Errors
Package Organization
Structure
Naming Conventions
- Package names: lowercase, single word
- Avoid stutter:
user.Usernotuser.UserModel - Use
internal/for private code - Keep
mainpackage minimal
Testing Patterns
Table-Driven Tests
Test Helpers
When to Use This Skill
- Designing Go APIs and packages
- Implementing concurrent systems
- Structuring Go projects
- Writing idiomatic Go code
- Refactoring Go codebases


