-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
handler_new.go
30 lines (24 loc) · 992 Bytes
/
handler_new.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
// +build go1.7
package kami
import (
"context"
"net/http"
)
// HandlerType is the type of Handlers and types that kami internally converts to
// ContextHandler. In order to provide an expressive API, this type is an alias for
// interface{} that is named for the purposes of documentation, however only the
// following concrete types are accepted:
// - types that implement http.Handler
// - types that implement ContextHandler
// - func(http.ResponseWriter, *http.Request)
// - func(context.Context, http.ResponseWriter, *http.Request)
type HandlerType interface{}
// ContextHandler is like http.Handler but supports context.
type ContextHandler interface {
ServeHTTPContext(context.Context, http.ResponseWriter, *http.Request)
}
// HandlerFunc is like http.HandlerFunc with context.
type HandlerFunc func(context.Context, http.ResponseWriter, *http.Request)
func (h HandlerFunc) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) {
h(ctx, w, r)
}