← ClaudeAtlas

golang-patternslisted

Idiomatic Go patterns, best practices, and conventions for building robust, efficient, and maintainable Go applications.
Nmor/the-claude-council · ★ 9 · Code & Development · score 69
Install: claude install-skill Nmor/the-claude-council
# Go Development Patterns > **Reuse-first** (per `~/.claude/rules-library/common/reuse-first.md`): > Before creating a new package, struct, interface, or helper > function, sweep `pkg/`, `internal/`, `lib/`. One source of > truth per concept (one `http.Client` factory, one > `slog.Handler`, one config loader, one error-wrap helper). For > shared behaviour across types, define a small interface and > implement once. Extend with a constructor option (functional- > options pattern) — never fork. Idiomatic Go patterns and best practices for building robust, efficient, and maintainable applications. ## When to Activate - Writing new Go code - Reviewing Go code - Refactoring existing Go code - Designing Go packages/modules ## Core Principles ### 1. Simplicity and Clarity Go favors simplicity over cleverness. Code should be obvious and easy to read. ```go // Good: Clear and direct func GetUser(id string) (*User, error) { user, err := db.FindUser(id) if err != nil { return nil, fmt.Errorf("get user %s: %w", id, err) } return user, nil } // Bad: Overly clever func GetUser(id string) (*User, error) { return func() (*User, error) { if u, e := db.FindUser(id); e == nil { return u, nil } else { return nil, e } }() } ``` ### 2. Make the Zero Value Useful Design types so their zero value is immediately usable without initialization. ```go // Good: Zero value is useful type Counter struct { mu