-
Notifications
You must be signed in to change notification settings - Fork 1
/
httpx.go
33 lines (26 loc) · 908 Bytes
/
httpx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// package httpx provides an extra layer of convenience over package http.
package httpx
import (
"net/http"
"context"
)
// Handler is represents a Handler that can take a context.Context as the
// first argument.
type Handler interface {
ServeHTTPContext(context.Context, http.ResponseWriter, *http.Request) error
}
// The HandlerFunc type is an adapter to allow the use of ordinary functions as
// httpx handlers. If f is a function with the appropriate signature,
// HandlerFunc(f) is a Handler object that calls f.
type HandlerFunc func(context.Context, http.ResponseWriter, *http.Request) error
// ServeHTTPContext calls f(ctx, w, r)
func (f HandlerFunc) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
return f(ctx, w, r)
}
// key used to store context values from within this package.
type key int
const (
varsKey key = iota
requestIDKey
routeKey
)