← ClaudeAtlas

go-idiomlisted

Enforces idiomatic Go style — name length scaled to scope, no stutter, useful zero values, guard clauses, correct defer placement, composition over inheritance, and doc comments in the required form. Use when writing, reviewing, or refactoring any Go code, and when the user asks whether something is idiomatic, mentions gofmt, go vet, golangci-lint, package naming, receiver names, struct embedding, or asks "is this Go-ish", "does this read like Go", "clean up this Go".
CasLubbers/code-design-skills · ★ 1 · Code & Development · score 62
Install: claude install-skill CasLubbers/code-design-skills
# Idiomatic Go ## Names scale with scope The greater the distance between declaration and use, the longer the name. Short names inside short scopes are correct Go, not laziness. ```go // Good — tight scope, short names for i, r := range records { if r.Total > max { max = r.Total } } // Good — package-level, long enough to stand alone const defaultDialTimeout = 30 * time.Second // Bad — ceremony inside a two-line loop for recordIndex, currentRecord := range records { ... } ``` Receivers get one or two letters, consistent across every method on the type: `func (s *Server) Start()`, never `func (this *Server)` or `func (server *Server)`. ## No stutter The package name is part of every identifier a caller reads. Do not repeat it. ```go // Bad — callers write http.HTTPServer, bytes.BytesBuffer package http type HTTPServer struct{} // Good — callers write http.Server, bytes.Buffer package http type Server struct{} ``` Same rule for functions: `user.NewUser()` should be `user.New()`. Package names are short, lowercase, single words, no underscores, no plurals: `store`, not `stores` or `store_utils`. ## Make the zero value useful A struct should be usable without a constructor wherever possible. ```go // Good — var buf bytes.Buffer works immediately var mu sync.Mutex var buf bytes.Buffer // Good — zero value is a ready cache type Cache struct { mu sync.Mutex m map[string][]byte // lazily initialised on first write } ``` Reach for `New…` only when construc