4 ms·
Probably something like: // h already has a context.Context in scope through similar func MyHandler (ctx context.Context, h http.Handler) http.Handler
by 2mur 12y ago
Probably something like:
// h already has a context.Context in scope through similar
func MyHandler (ctx context.Context, h http.Handler) http.Handler {
return http.HandlerFunc(func (rw http.ResponseWriter, req *http.Request) {
// do stuff before handler
h.serveHttp(rw, req)
// do stuff after handler
})
}
then you can just chain your handlers and pass through a shared context
- carbocation 12y agoIn Interpose, that's exactly the pattern I use to pull in methods that require context while still satisfying the http.Handler interface (e.g., https://github.com/carbocation/interpose/blob/master/examples/menagerie/ascendinginteger.go https://github.com/carbocation/interpose/blob/master/example... ), so it seems that this pattern would work well with Google's Context.