This is part 2 of 2 in the series Go HTTP middleware from scratch. If you're new to Go types, → read part 1 first.
The same code keeps showing up everywhere
You're building an HTTP server. Every request needs a unique ID for tracing. Every request needs to check authentication. Every request needs its duration logged. The naive approach: copy that code into every handler.
// Without middleware — same boilerplate in every single handler
func getUserHandler(w http.ResponseWriter, r *http.Request) {






