HTTP Servers with net/http: ServeMux Pattern Routing, Handlers, Middleware and Timeouts
For an HTTP service in Go the standard library is enough: since 1.22 ServeMux matches method and wildcard patterns with a most-specific-wins rule, and middleware is an ordinary function that wraps a handler. Moving the Bookstore API into the httpapi package, RequestID and Logging middleware, CORS and CrossOriginProtection, the 307 redirect, the pattern conflict panic, WriteTimeout not stopping the handler, and http.Server timeouts against slowloris.
15 Nov 2026
·
13 min
·
6