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{})
| 25 | // func(Context, http.ResponseWriter, *http.Request) |
| 26 | // func(Context, http.ResponseWriter, *http.Request, func()) |
| 27 | func 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. |
| 55 | func Compose(stack ...interface{}) ContextHandler { |