https://github.com/go-swagger/go-swagger/blob/master/examples/oauth2/restapi/configure_oauth_sample.go
谁能解释这段代码的用途?
// This demonstrates how to enrich and pass custom context keys.
// In this case, we cache the current responseWriter in context.
type customContextKey int8
const (
_ customContextKey = iota
ctxResponseWriter
)
// The middleware configuration is for the handler executors. These do not apply to the swagger.json document.
// The middleware executes after routing but before authentication, binding and validation
func setupMiddlewares(handler http.Handler) http.Handler {
ourFunc := func(w http.ResponseWriter, r *http.Request) {
rctx := context.WithValue(r.Context(), ctxResponseWriter, w)
handler.ServeHTTP(w, r.WithContext(rctx))
}
return http.HandlerFunc(ourFunc)
}
丰富和传递自定义上下文键是什么?
一只萌萌小番薯
相关分类