Add pre1.7 compat for new-style context mangement

master
Kevin Conway 6 years ago
parent 98eb90a4e5
commit a4a0e7f319

@ -0,0 +1,19 @@
// +build go1.7
package xhandler
import (
"net/http"
"context"
)
// New creates a conventional http.Handler injecting the provided root
// context to sub handlers. This handler is used as a bridge between conventional
// http.Handler and context aware handlers.
func New(ctx context.Context, h HandlerC) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
h.ServeHTTPC(ctx, w, r.WithContext(ctx))
})
}

@ -0,0 +1,19 @@
// +build !go1.7
package xhandler
import (
"net/http"
"golang.org/x/net/context"
)
// New creates a conventional http.Handler injecting the provided root
// context to sub handlers. This handler is used as a bridge between conventional
// http.Handler and context aware handlers.
func New(ctx context.Context, h HandlerC) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
h.ServeHTTPC(ctx, w, r)
})
}

@ -32,11 +32,3 @@ func (f HandlerFuncC) ServeHTTPC(ctx context.Context, w http.ResponseWriter, r *
f(ctx, w, r)
}
// New creates a conventional http.Handler injecting the provided root
// context to sub handlers. This handler is used as a bridge between conventional
// http.Handler and context aware handlers.
func New(ctx context.Context, h HandlerC) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
h.ServeHTTPC(ctx, w, r.WithContext(ctx))
})
}

Loading…
Cancel
Save