// Helper function to chain multiple handlers in a single call.
357928
func ChainHandlers(h ...http.Handler) ChainableHandler {
	return &chainHandler{
		http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			for _, v := range h {
				v.ServeHTTP(w, r)
			}
		}),
	}
}
893113
func (s *Server) Handle(method string, handlerFunc interface{}) {
	addHandler(s.handlers, method, handlerFunc)
}
1077961
func (c Chain) HandlerC(xh HandlerC) HandlerC {
	for i := len(c) - 1; i >= 0; i-- {
		xh = c[i](xh)
	}
	return xh
}
1061942
func (a *API) AddHandler(f func(http.ResponseWriter, *http.Request)) {
	a.handlers = append(a.handlers, f)
}
240199
func (o *Options) Handler(handler http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		initOnce.Do(func() {
			options = make(map[*http.Request]*Options)
			responded = make(map[*http.Request]bool)
		})
		mutex.Lock()
		options[r] = o
		mutex.Unlock()
		defer func() {
			mutex.Lock()
			delete(options, r)
			delete(responded, r)
			mutex.Unlock()
		}()
		handler.ServeHTTP(w, r)
	})
}
1112856
func (msg MultiServiceGenerator) Handle() Handle {
	mh := make(MultiHandle, len(msg))
	for i, sg := range msg {
		mh[i] = sg.Handle()
	}
	return mh
}
1011344
func (c Chain) Handler(h http.Handler) http.Handler {
	if h == nil {
		h = http.DefaultServeMux
	}

	for i := len(c.mw) - 1; i >= 0; i-- {
		h = c.mw[i](h)
	}
	return h
}
182541
func (h *AsyncHttpHandler) handle(f func() (string, error)) {
	go func() {
		logger.Info("Started job %v", h.id)

		ts := time.Now()
		url, err := f()
		logger.Info("Completed job %v in %v", h.id, time.Since(ts))

		if err != nil {
			h.CompletedWithError(err)
		} else if url != "" {
			h.CompletedWithLocation(url)
		} else {
			h.Completed()
		}
	}()
}
820266
func (r *Registry) applyHandlers(f func(o RegisterObject)) {
	r.m.Lock()
	handlers := make([]RegisterObject, 0, len(r.handlers))
	for _, handler := range r.handlers {
		handlers = append(handlers, handler)
	}
	r.m.Unlock()

	for i := range handlers {
		f(handlers[i])
	}
}
721811
func (r *HandlerRegistry) Handler(cname string) *Handler {
	r.mutex.Lock()
	h := r.handlers[cname]
	r.mutex.Unlock()
	return h
}
932677
func (r *Router) chain() http.Handler {
	var final http.Handler

	final = r.router
	mw := r.allMiddleware()
	for i := len(mw) - 1; i >= 0; i-- {
		final = mw[i](final)
	}

	return final
}
1319529
func (b *MultiHandler) Handle(rec *Record) {
	wg := sync.WaitGroup{}
	wg.Add(len(b.handlers))
	for _, handler := range b.handlers {
		go func(handler Handler) {
			handler.Handle(rec)
			wg.Done()
		}(handler)
	}
	wg.Wait()
}
2675
func chainMiddleware(el *list.Element) http.HandlerFunc {
	// The last element of the middlewares chain is nil.
	if el == nil {
		return func(rw http.ResponseWriter, r *http.Request) {}
	}
	return func(rw http.ResponseWriter, r *http.Request) {
		el.Value.(Middleware).ServeHTTP(rw, r, chainMiddleware(el.Next()))
	}
}
1208890
func (r *Router) HandlerFunc(method string, path string, handler http.HandlerFunc) {
	r.Router.HandlerFunc(method, path, handler)
}
419798
func (r *FlatChain) LinkHandleFunc(h http.HandlerFunc) FlatChains {
	fh := FlatChainWrap(h, r.log)
	r.Link(fh)
	return fh
}
1047902
func (handler *handler) Handle(_ <-chan struct{}, applications []string) error {
	return handler.config.Facade.Rescale(applications)
}
805040
func combineHandlers(h1 []Handler, h2 []Handler) []Handler {
	hh := make([]Handler, len(h1)+len(h2))
	copy(hh, h1)
	copy(hh[len(h1):], h2)
	return hh
}