Handler returns an HTTP handler for function f. See the package doc for details on allowed signatures for f. If f returns a non-nil error, the handler will call errFunc.
(f interface{}, errFunc ErrorWriter)
| 30 | // See the package doc for details on allowed signatures for f. |
| 31 | // If f returns a non-nil error, the handler will call errFunc. |
| 32 | func Handler(f interface{}, errFunc ErrorWriter) (http.Handler, error) { |
| 33 | fv := reflect.ValueOf(f) |
| 34 | hasCtx, inType, err := funcInputType(fv) |
| 35 | if err != nil { |
| 36 | return nil, err |
| 37 | } |
| 38 | |
| 39 | h := &handler{fv, inType, hasCtx, errFunc} |
| 40 | return h, nil |
| 41 | } |
| 42 | |
| 43 | func (h *handler) ServeHTTP(w http.ResponseWriter, req *http.Request) { |
| 44 | var a []reflect.Value |