MCPcopy Create free account
hub / github.com/VividCortex/siesta / ToContextHandler

Function ToContextHandler

handler.go:27–52  ·  view source on GitHub ↗

ToContextHandler transforms f into a ContextHandler. f must be a function with one of the following signatures: func(http.ResponseWriter, *http.Request) func(http.ResponseWriter, *http.Request, func()) func(Context, http.ResponseWriter, *http.Request) func(Context, http.ResponseWriter, *http.Request

(f interface{})

Source from the content-addressed store, hash-verified

25// func(Context, http.ResponseWriter, *http.Request)
26// func(Context, http.ResponseWriter, *http.Request, func())
27func ToContextHandler(f interface{}) ContextHandler {
28 switch t := f.(type) {
29 case func(Context, http.ResponseWriter, *http.Request, func()):
30 return ContextHandler(t)
31 case ContextHandler:
32 return t
33 case func(Context, http.ResponseWriter, *http.Request):
34 return func(c Context, w http.ResponseWriter, r *http.Request, q func()) {
35 t(c, w, r)
36 }
37 case func(http.ResponseWriter, *http.Request, func()):
38 return func(c Context, w http.ResponseWriter, r *http.Request, q func()) {
39 t(w, r, q)
40 }
41 case func(http.ResponseWriter, *http.Request):
42 return func(c Context, w http.ResponseWriter, r *http.Request, q func()) {
43 t(w, r)
44 }
45 case http.Handler:
46 return func(c Context, w http.ResponseWriter, r *http.Request, q func()) {
47 t.ServeHTTP(w, r)
48 }
49 default:
50 panic(ErrUnsupportedHandler)
51 }
52}
53
54// Compose composes multiple ContextHandlers into a single ContextHandler.
55func Compose(stack ...interface{}) ContextHandler {

Callers 6

ComposeFunction · 0.85
addToChainFunction · 0.85
RouteMethod · 0.85
SetNotFoundMethod · 0.85
fakeHandlerFunction · 0.85

Calls 2

ContextHandlerFuncType · 0.85
ServeHTTPMethod · 0.45

Tested by 2

fakeHandlerFunction · 0.68