Go HTTP middleware explained: what it is, how it works, and how to build your own (opens in new tab)
This is part 2 of 2 in the series Go HTTP middleware from scratch. If you're new to Go types, → . 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) { // Auth chec...
Read the original article