# Go (stdlib-first) — Claude Code rules ## Module hygiene - Go 1.22+ — use the standard library `net/http.ServeMux` (method + pattern routing). No gin/echo/chi unless the requirements clearly justify it. - `go vet ./...` and `staticcheck ./...` must pass. - `gofmt -s` + `goimports` formatting is mandatory. ## Errors - Always wrap with `fmt.Errorf("...: %w", err)` so callers can `errors.Is` / `errors.As`. - Sentinel errors are package-level `var ErrFoo = errors.New("...")`. Typed errors implement `Error()` and may implement `Unwrap()`. - Don't ignore errors. If genuinely OK to drop, name the variable `_` with a comment. ## Concurrency - Pass `context.Context` as the first param of any blocking function. Never store it in a struct. - Use `errgroup.Group` (from `golang.org/x/sync/errgroup`) for fan-out + first-error semantics. - Goroutines must have a clear shutdown path. No "fire and forget" without `context.Cancel` plumbing. ## HTTP - `http.ServeMux` with method-aware patterns (`r.HandleFunc("GET /users/{id}", h)`). - Handlers take `(w http.ResponseWriter, r *http.Request)` and read deadlines from `r.Context()`. - JSON via `encoding/json` with explicit struct tags. No reflection-heavy frameworks. ## What not to do - Don't introduce a third-party router unless there's a hard requirement. - Don't use `panic` for control flow. - Don't hand-roll struct tag-less JSON.