Home › Go › Go stdlib HTTP service AGENTS.md

Go stdlib HTTP service AGENTS.md

AGENTS.md for Go 1.27 services using only net/http, slog, and database/sql or pgx, with no web framework.

AGENTS.mdGo

How to use

Save this as AGENTS.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

AGENTS.mdDownload  
# AGENTS.md: Go service (standard library)

## Commands
`go build ./...` · `go test -race ./...` · `go vet ./...` · `golangci-lint run` · run: `go run ./cmd/server`

## Layout
- `cmd/server/main.go`: parse config, build dependencies, call `run(ctx)`; `main` only handles exit codes.
- `internal/http/`: routes and handlers; `internal/<domain>/`: logic and storage.

## HTTP
- Routes on `http.NewServeMux()` with method + path patterns: `mux.HandleFunc("POST /orders/{id}/cancel", h.cancel)`; read params with `r.PathValue`.
- Middleware is `func(http.Handler) http.Handler`, composed in one place (logging, recovery, auth, request ID).
- Decode JSON with `json.NewDecoder(http.MaxBytesReader(w, r.Body, 1<<20))` and `DisallowUnknownFields()`; validate before use.
- One `writeJSON(w, status, v)` and `writeError` helper for consistent responses.
- `http.Server` with `ReadHeaderTimeout`, `ReadTimeout`, `WriteTimeout`, `IdleTimeout`; graceful `Shutdown` on signal via `signal.NotifyContext`.

## Data
- `database/sql` or `pgx/v5` pool created once; queries take `ctx`; parameterized only. Consider `sqlc` for typed queries if it's already set up.

## Style
- Errors wrapped with context (`%w`); log once at the edge with `slog`, don't log-and-return.
- No globals for dependencies; pass a struct with what each handler needs.

## Done
Build, vet, lint, and race tests pass; each handler has an `httptest` test.

More: all Go rules · all AGENTS.md rules

Related rules

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

Go CLI (Cobra) CLAUDE.md

CLAUDE.md for command-line tools in Go 1.27 with Cobra: commands, flags, output formats, exit codes, and tests.

Claude Code (CLAUDE.md)Go

Go concurrency Windsurf rules

Windsurf rules for safe Go concurrency: goroutine lifetimes, context cancellation, errgroup, channels, and the race detector.

WindsurfGo

Go + Gin web API Windsurf rules

Windsurf rules for Go 1.27 REST APIs built with Gin: handlers, binding/validation, middleware, and tests.

WindsurfGo

Go gRPC service rules

Cursor rules for gRPC services in Go with protobuf, buf for codegen and linting, interceptors, and status errors.

CursorGo

Go Copilot path instructions

Path-specific Copilot instructions (.instructions.md) for Go 1.27 code: errors, context, stdlib routing, and tests.

GitHub CopilotGo

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.