// FaviconHandlerFunc is the same as FaviconHandler, it is just a convenience
// signature that accepts a func(http.ResponseWriter, *http.Request) instead of
// a http.Handler interface. It saves the boilerplate http.HandlerFunc() cast.
545231
func FaviconHandlerFunc(h http.HandlerFunc, path string, maxAge time.Duration) http.HandlerFunc {
	return FaviconHandler(h, path, maxAge)
}
502653
func WrapHandler(h http.Handler) HandlerFunc {
	return func(c Context) error {
		h.ServeHTTP(c.Response(), c.Request())
		return nil
	}
}
496001
func (c *Characteristic) HandleNotifyFunc(f func(r Request, n Notifier)) {
	c.HandleNotify(NotifyHandlerFunc(f))
}
177648
func (r *Router) GetFunc(pattern string, fn http.HandlerFunc) Route {
	return r.Get(pattern, http.HandlerFunc(fn))
}
376339
func (msm *MultistreamMuxer) AddHandlerWithFunc(protocol string, match func(string) bool, handler HandlerFunc) {
	msm.handlerlock.Lock()
	defer msm.handlerlock.Unlock()

	msm.removeHandler(protocol)
	msm.handlers = append(msm.handlers, Handler{
		MatchFunc: match,
		Handle:    handler,
		AddName:   protocol,
	})
}
172764
func (r *Route) GetFunc(f http.HandlerFunc) *Route {
	return r.Get(http.HandlerFunc(f))
}
48592
func Prefix(prefix string, handler Handler) HandlerFunc {
	return func(ctx *Context) {
		if strings.HasPrefix(ctx.Req().URL.Path, prefix) {
			handler.Handle(ctx)
			return
		}

		ctx.Next()
	}
}
454309
func (k *Kite) HandleFunc(method string, handler HandlerFunc) *Method {
	return k.addHandle(method, handler)
}
1178273
func (r *Router) HandleFunc(event string, fn func(http.ResponseWriter, *http.Request)) {
	r.Handle(event, http.HandlerFunc(fn))
}
1284190
func (c *Cors) HandlerFunc(w http.ResponseWriter, r *http.Request) {
	if r.Method == http.MethodOptions && r.Header.Get("Access-Control-Request-Method") != "" {
		c.logf("HandlerFunc: Preflight request")
		c.handlePreflight(w, r)
	} else {
		c.logf("HandlerFunc: Actual request")
		c.handleActualRequest(w, r)
	}
}
644051
func StaticFileHandler(filename string) http.Handler {
	fcontents, err := ioutil.ReadFile(filename) // cache the contents of the file, this is the difference from net/http's impl, this is used only for static files, like favicons, css and so on
	if err != nil {
		return errorHandler(http.StatusBadRequest)
	}
	return StaticContentHandler(fcontents, TypeByExtension(filename))
}
110857
func favIcon(w *rest.ResponseWriter, r *rest.Request) {
	http.ServeFile(
		w.ResponseWriter,
		r.Request,
		staticRoot()+"/ico/favicon.png")
}
235684
func FaviconHandler(favPath string) http.Handler {
	f, err := os.Open(favPath)
	if err != nil {
		panic(errFileOpen.Format(favPath, err.Error()))
	}
	defer f.Close()
	fi, _ := f.Stat()
	if fi.IsDir() { // if it's dir the try to get the favicon.ico
		fav := path.Join(favPath, "favicon.ico")
		f, err = os.Open(fav)
		if err != nil {
			//we try again with .png
			favPath = path.Join(favPath, "favicon.png")
			return FaviconHandler(favPath)
		}
		favPath = fav
		fi, _ = f.Stat()
	}

	cType := TypeByExtension(favPath)
	// copy the bytes here in order to cache and not read the ico on each request.
	cacheFav := make([]byte, fi.Size())
	if _, err = f.Read(cacheFav); err != nil {
		panic(errFileRead.Format(favPath, "Favicon: "+err.Error()))
	}

	return StaticContentHandler(cacheFav, cType)
}
405523
func (sm *ServeMux) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request) error) {
	sm.ServeMux.Handle(pattern, sm.HandlerFunc(handler))
}
927820
func (m *Mux) HandleFunc(expr string, handler func(http.ResponseWriter, *http.Request)) error {
	return m.Handle(expr, http.HandlerFunc(handler))
}
606632
func imageHandler(w http.ResponseWriter, r *http.Request) {
	data, ok := images[strings.TrimPrefix(r.URL.Path, "/image/")]
	if !ok {
		http.NotFound(w, r)
		return
	}
	if err := imageTemplate.Execute(w, data); err != nil {
		log.Println(err)
	}
}
1353350
func MakeHandler(app *App, fn HandlerFunc, spec Spec) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var response interface{}
		var status int
		var err error

		start := time.Now()
		if err = parseForm(r); err != nil {
			err = fmt.Errorf("Failed to parse request form: %v", err)
			response = Response{"message": err.Error()}
			status = http.StatusInternalServerError
		} else {
			response, err = fn(w, r, DecodeParams(mux.Vars(r)))
			if err != nil {
				response, status = responseAndStatusFor(err)
			} else {
				status = http.StatusOK
			}
		}
		elapsedTime := time.Since(start)
		LogRequest(r, status, elapsedTime, err)
		app.stats.TrackRequest(spec.MetricName, status, elapsedTime)

		Reply(w, response, status)
	}
}