Middleware is just a function that accepts and returns an http.Handler.
The Shape
type Middleware func(http.Handler) http.Handler
func Chain(h http.Handler, m ...Middleware) http.Handler {
for i := len(m) - 1; i >= 0; i-- {
h = m[i](h)
}
return h
}
This keeps dependencies explicit while preserving standard-library compatibility.
Request IDs
Generate an ID at the edge, store it in context, and write it to every log line produced during the request.
Recovery
Panic recovery should be the last safety net, not an error handling strategy. Log the panic, return a generic 500, and keep sensitive details out of the response.