Home › Go › Go backend CLAUDE.md
Go backend CLAUDE.md
CLAUDE.md for idiomatic Go HTTP services using the standard library, sqlc and table-driven tests.
Claude Code (CLAUDE.md)Go
How to use
Save this as CLAUDE.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.
CLAUDE.mdDownload # CLAUDE.md
## Commands
- Build: `go build ./...` · Test: `go test ./... -race` · Lint: `golangci-lint run`
- Generate SQL code: `sqlc generate` (after editing `db/queries/*.sql`)
## Layout
- `cmd/server/main.go` wiring only · `internal/http` handlers · `internal/service` logic · `internal/db` sqlc output (do not edit)
## Style
- Idiomatic Go: small interfaces defined by the consumer, accept interfaces return structs.
- Use `net/http` with Go 1.22+ routing patterns (`mux.HandleFunc("GET /users/{id}", ...)`). No web framework unless asked.
- Pass `context.Context` as the first arg through every I/O call.
- Wrap errors: `fmt.Errorf("load user %d: %w", id, err)`. Never ignore an error; never `panic` in request paths.
- Use `log/slog` for structured logs.
- Tests are table-driven with `t.Run`; use `httptest` for handlers.
## Before finishing
- `gofmt` clean, `go vet` clean, tests pass with `-race`.