// FuncHandler takes a func and its id and converts them into a FuncTaskHandler
359594
func FuncHandler(f func(*Task) error, id string) FuncTaskHandler {
	return FuncTaskHandler{
		f:  f,
		id: id,
	}
}
1035712
func (c *Client) InMsgHandler(handler func(m []models.Message) error) {
	c.router.Request("msg.recv", func(ctx *neptulon.ReqCtx) error {
		var msg []models.Message
		if err := ctx.Params(&msg); err != nil {
			return fmt.Errorf("client: msg.recv: error reading request params: %v", err)
		}

		if err := handler(msg); err != nil {
			return err
		}

		ctx.Res = ACK
		return ctx.Next()
	})
}
879118
func FlatHandlerFuncWrap(h http.HandlerFunc) FlatHandler {
	return (func(c *Context, nx NextHandler) {
		h(c.Res, c.Req)
		nx(c)
	})
}
262412
func NewTextHandler(t *template.Template, output TextOutput) *TextHandler {
	return &TextHandler{template: t, output: output}
}
1312245
func (c *Client) UseHandler(phase string, fn context.HandlerFunc) *Client {
	c.Middleware.UseHandler(phase, fn)
	return c
}
1000965
func SimplePanicHandler(w http.ResponseWriter, r *http.Request, err interface{}) {
	w.WriteHeader(http.StatusInternalServerError)
}
25231
func (s *OscDispatcher) AddMsgHandler(addr string, handler HandlerFunc) error {
	if addr == "*" {
		s.defaultHandler = handler
		return nil
	}
	for _, chr := range "*?,[]{}# " {
		if strings.Contains(addr, fmt.Sprintf("%c", chr)) {
			return errors.New("OSC Address string may not contain any characters in \"*?,[]{}#")
		}
	}

	if addressExists(addr, s.handlers) {
		return errors.New("OSC address exists already")
	}

	s.handlers[addr] = handler
	return nil
}
1027941
func (mw *Middleware) UseHandler(handler http.Handler) {
	x := func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
			handler.ServeHTTP(w, req)
			next.ServeHTTP(w, req)
		})
	}

	mw.Use(x)
}
502653
func WrapHandler(h http.Handler) HandlerFunc {
	return func(c Context) error {
		h.ServeHTTP(c.Response(), c.Request())
		return nil
	}
}
275117
func (s *StreamingRpcRegistry) GetHandler(method string) (StreamingRpcHandler, error) {
	h, ok := s.registry[method]
	if !ok {
		return nil, fmt.Errorf("%s: %q", ErrUnknownMethod, method)
	}

	return h, nil
}
571771
func SlowHandler(fn http.HandlerFunc, max time.Duration, cb func(r *http.Request, t time.Duration)) http.HandlerFunc {
	return func(w http.ResponseWriter, req *http.Request) {
		t0 := time.Now()
		fn(w, req)
		t := time.Since(t0)
		if t > max {
			cb(req, t)
		}
	}
}
1208890
func (r *Router) HandlerFunc(method string, path string, handler http.HandlerFunc) {
	r.Router.HandlerFunc(method, path, handler)
}
926259
func PKTagHandler(ctx *tagContext) error {
	ctx.col.IsPrimaryKey = true
	ctx.col.Nullable = false
	return nil
}
1286822
func ErrorHandler(eh ErrorHandlerFunc) func(*Configuration) error {
	return func(c *Configuration) error {
		c.errorHandler = eh
		return nil
	}
}
710797
func (m *Mux) UseHandler(phase string, fn c.HandlerFunc) *Mux {
	m.Middleware.UseHandler(phase, fn)
	return m
}
553960
func MakeHTTPHandler(handlerFunc httpAPIFunc) http.HandlerFunc {
	// Create a closure and return an anonymous function
	return func(w http.ResponseWriter, r *http.Request) {
		// Call the handler
		resp, err := handlerFunc(w, r, mux.Vars(r))
		if err != nil {
			// Log error
			log.Errorf("Handler for %s %s returned error: %s", r.Method, r.URL, err)

			if resp == nil {
				// Send HTTP response
				http.Error(w, err.Error(), http.StatusInternalServerError)
			} else {
				// Send HTTP response as Json
				content, err := json.Marshal(resp)
				if err != nil {
					http.Error(w, err.Error(), http.StatusInternalServerError)
					return
				}

				w.WriteHeader(http.StatusInternalServerError)
				w.Write(content)
			}
		} else {
			// Send HTTP response as Json
			err = writeJSON(w, http.StatusOK, resp)
			if err != nil {
				http.Error(w, err.Error(), http.StatusInternalServerError)
				return
			}
		}
	}
}
845104
func FSHandler(fs *FS, fail http.HandlerFunc) RHandler {
	return func(res http.ResponseWriter, req *http.Request, c Collector) {
		strip := path.Clean(fmt.Sprintf("/%s/", fs.Strip))
		requested := reggy.CleanPath(req.URL.Path)
		file := strings.TrimPrefix(requested, strip)

		fi, err := fs.Open(file)

		if err != nil {
			if fail != nil {
				fail(res, req)
			} else {
				http.NotFound(res, req)
			}
			return
		}

		ext := strings.ToLower(filepath.Ext(file))

		stat, err := fi.Stat()

		if err != nil {
			if fail != nil {
				fail(res, req)
			} else {
				http.NotFound(res, req)
			}
			return
		}

		// var cext string
		cext := mime.TypeByExtension(ext)

		// log.Printf("Type ext: %s -> %s", ext, cext)
		if cext == "" {
			if types, ok := mediaTypes[ext]; ok {
				cext = types
			} else {
				cext = "text/plain"
			}
		}

		res.Header().Set("Content-Type", cext)

		if fs.Header != nil {
			for m, v := range fs.Header {
				for _, va := range v {
					res.Header().Add(m, va)
				}
			}
		}

		http.ServeContent(res, req, stat.Name(), stat.ModTime(), fi)
	}
}