import ( "net/http" "context" ) func myHandler(w http.ResponseWriter, r *http.Request) { ctx := r.Context() userID := getUserIdFromToken(ctx.Value("auth_token")) ... } func authenticate(next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { authToken := r.Header.Get("Authorization") ctx := context.WithValue(r.Context(), "auth_token", authToken) next(w, r.WithContext(ctx)) } }In the above example, the authenticate middleware obtains the auth token from the request header and stores it in the Request Context. Later, the value is retrieved in the request handler function using the context package. The Request Context is an invaluable feature of the Go net/http package and is used extensively in many web applications.