Add pre1.7 compat for new-style context mangement
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)
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue