
Golang Patterns
- 10.7k installs
- 238k repo stars
- Updated August 5, 2026
- affaan-m/everything-claude-code
Go-specific design patterns and idioms for building idiomatic, maintainable Go code
About
This skill teaches Go-specific design patterns including functional options, small interfaces, dependency injection, concurrency patterns (worker pools, context propagation), error handling (wrapping, custom errors, sentinels), package organization (cmd/internal/pkg structure), and testing strategies (table-driven tests, test helpers). Developers use it when designing Go APIs and packages, implementing concurrent systems, structuring projects, or refactoring codebases to follow idiomatic Go conventions. Key workflows cover constructor patterns for flexible configuration, defining interfaces at point of use for loose coupling, explicit dependency injection, safe concurrency with sync.WaitGroup and channels, and structured error handling with fmt.Errorf wrapping.
- Functional options pattern for backward-compatible constructor configuration
- Small, focused interfaces defined at point of use for testability and loose coupling
- Concurrency patterns including worker pools and context propagation as first parameter
- Error handling with wrapping (fmt.Errorf %w), custom types, and sentinel errors (errors.Is)
- Project structure using cmd/, internal/, and pkg/ directories with table-driven tests
Golang Patterns by the numbers
- 10,694 all-time installs (skills.sh)
- +261 installs in the week ending Aug 5, 2026 (Skillselion tracking)
- Ranked #18 of 98 Go skills by installs in the Skillselion catalog
- Security screen: LOW risk (skills.sh audit)
- Data as of Aug 5, 2026 (Skillselion catalog sync)
golang-patterns capabilities & compatibility
- Capabilities
- provide functional options pattern templates for · guide interface design at point of use · implement dependency injection patterns · design worker pool and context based concurrency · demonstrate error wrapping and custom error type · suggest project structure with cmd/internal/pkg · generate table driven test templates
- Use cases
- api development · code review · refactoring
npx skills add https://github.com/affaan-m/everything-claude-code --skill golang-patternsAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 10.7k |
|---|---|
| repo stars | ★ 238k |
| Security audit | 3 / 3 scanners passed |
| Last updated | August 5, 2026 |
| Repository | affaan-m/everything-claude-code ↗ |
What it does
Apply Go-specific design patterns and idioms when building APIs, services, and concurrent systems.
Who is it for?
Building Go APIs, services, and concurrent systems; refactoring Go codebases; designing public packages
Skip if: Frontend development; single-file scripts; non-concurrent applications with minimal structure requirements
When should I use this skill?
Designing Go APIs and packages, implementing concurrent systems, structuring new Go projects, writing idiomatic Go code, refactoring existing Go codebases
What you get
Apply functional options, small interfaces, dependency injection, concurrency patterns, and proper error handling to build well-structured Go services
- Idiomatic Go code following design patterns
- Well-structured packages with clear dependencies
- Safe concurrent implementations
By the numbers
- 7 major pattern categories covered: functional options, small interfaces, dependency injection, concurrency, error handl
- Includes 3 error handling approaches: wrapping with fmt.Errorf %w, custom error types, sentinel errors with errors.Is
- 2 core concurrency patterns documented: worker pools with sync.WaitGroup and context propagation
Files
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:
type Option func(*Server)
func WithPort(port int) Option {
return func(s *Server) { s.port = port }
}
func NewServer(opts ...Option) *Server {
s := &Server{port: 8080}
for _, opt := range opts {
opt(s)
}
return s
}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
// Good: Small, focused interface defined at point of use
type UserStore interface {
GetUser(id string) (*User, error)
}
func ProcessUser(store UserStore, id string) error {
user, err := store.GetUser(id)
// ...
}Benefits:
- Easier testing and mocking
- Loose coupling
- Clear dependencies
Dependency Injection
Use constructor functions to inject dependencies:
func NewUserService(repo UserRepository, logger Logger) *UserService {
return &UserService{
repo: repo,
logger: logger,
}
}Pattern:
- Constructor functions (New* prefix)
- Explicit dependencies as parameters
- Return concrete types
- Validate dependencies in constructor
Concurrency Patterns
Worker Pool
func workerPool(jobs <-chan Job, results chan<- Result, workers int) {
var wg sync.WaitGroup
for i := 0; i < workers; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for job := range jobs {
results <- processJob(job)
}
}()
}
wg.Wait()
close(results)
}Context Propagation
Always pass context as first parameter:
func FetchUser(ctx context.Context, id string) (*User, error) {
// Check context cancellation
select {
case <-ctx.Done():
return nil, ctx.Err()
default:
}
// ... fetch logic
}Error Handling
Error Wrapping
if err != nil {
return fmt.Errorf("failed to fetch user %s: %w", id, err)
}Custom Errors
type ValidationError struct {
Field string
Msg string
}
func (e *ValidationError) Error() string {
return fmt.Sprintf("%s: %s", e.Field, e.Msg)
}Sentinel Errors
var (
ErrNotFound = errors.New("not found")
ErrInvalid = errors.New("invalid input")
)
// Check with errors.Is
if errors.Is(err, ErrNotFound) {
// handle not found
}Package Organization
Structure
project/
├── cmd/ # Main applications
│ └── server/
│ └── main.go
├── internal/ # Private application code
│ ├── domain/ # Business logic
│ ├── handler/ # HTTP handlers
│ └── repository/ # Data access
└── pkg/ # Public librariesNaming Conventions
- Package names: lowercase, single word
- Avoid stutter:
user.Usernotuser.UserModel - Use
internal/for private code - Keep
mainpackage minimal
Testing Patterns
Table-Driven Tests
func TestValidate(t *testing.T) {
tests := []struct {
name string
input string
wantErr bool
}{
{"valid", "test@example.com", false},
{"invalid", "not-an-email", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := Validate(tt.input)
if (err != nil) != tt.wantErr {
t.Errorf("got error %v, wantErr %v", err, tt.wantErr)
}
})
}
}Test Helpers
func testDB(t *testing.T) *sql.DB {
t.Helper()
db, err := sql.Open("sqlite3", ":memory:")
if err != nil {
t.Fatalf("failed to open test db: %v", err)
}
t.Cleanup(func() { db.Close() })
return db
}When to Use This Skill
- Designing Go APIs and packages
- Implementing concurrent systems
- Structuring Go projects
- Writing idiomatic Go code
- Refactoring Go codebases
Related skills
Forks & variants (1)
Golang Patterns has 1 known copy in the catalog totaling 1.5k installs. They canonicalize to this original listing.
- affaan-m - 1.5k installs
How it compares
Pick golang-patterns over general backend skills when the language is Go and the goal is idiomatic style, not framework-agnostic API design.
FAQ
What is the functional options pattern?
A pattern using Option functions to enable flexible, backward-compatible constructor configuration without positional parameters. Pass ...Option variadic arguments to constructors for optional settings.
Why define interfaces at point of use?
Interfaces defined where they are consumed enable loose coupling, easier testing/mocking, and self-document what types actually need to implement. Accept interfaces, return concrete structs.
How do I safely handle concurrency in Go?
Use sync.WaitGroup for goroutine coordination, pass context.Context as first parameter for cancellation, use channels for communication, and always check context cancellation with select/ctx.Done().