$ recombobulate _
home / tips / use-claude-to-write-go-http-handlers
0

Use Claude to Write Go HTTP Handlers

bagwaa @bagwaa · Mar 26, 2026 · Workflows
use-claude-to-write-go-http-handlers

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.

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Scan Pending Changes for Security Issues with /security-review

The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.

bagwaa @bagwaa · 1 hour ago
0
Run Setup Scripts on Every Session with the SessionStart Hook

The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.

bagwaa @bagwaa · 1 hour ago
0
Write Property-Based Tests with fast-check and Claude

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.

bagwaa @bagwaa · 2 hours ago