Go's net/http patterns are consistent, but writing idiomatic handlers — with context propagation, structured errors, and clean JSON encoding — is repetitive. Claude nails the idioms.
claude "Write a Go HTTP handler for a POST /users endpoint. It should decode a JSON body, validate the required fields, insert into Postgres using pgx, and return appropriate status codes. Use the standard library only."
Claude will produce a handler that handles decode errors, validation, DB errors, and success responses cleanly — with no magic:
func (h *UserHandler) Create(w http.ResponseWriter, r *http.Request) {
var req CreateUserRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, "invalid request body", http.StatusBadRequest)
return
}
if req.Email == "" {
http.Error(w, "email is required", http.StatusUnprocessableEntity)
return
}
// ...
}
For router-specific patterns, be explicit about what you're using:
claude "Write a Chi router middleware that logs request duration and status code using slog. Apply it to all routes except /health."
Go rewards consistency — Claude delivers it every time.
Log in to leave a comment.
The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.
The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.
Ask Claude to write property-based tests for your functions using fast-check — it identifies the mathematical invariants in your code and generates tests that cover inputs you'd never enumerate by hand.