// FlatHandleHandler returns a flatchain that wraps a http.Handler
2454
func FlatHandleHandler(methods, pattern string, r http.Handler, lg *log.Logger) FlatChains {
	return FlatRoute(methods, pattern, FlatHandlerWrap(r), lg)
}
370026
func MakeHandler() *http.Handler {
	api := rest.NewApi()

	authMiddleware, err := CreateAuthMiddleware()
	if err != nil {
		panic(err)
	}

	api.Use(&rest.IfMiddleware{
		// Only authenticate non login or register requests
		Condition: func(request *rest.Request) bool {
			return (request.URL.Path != variables.APIPathLoginUserServer) && (request.URL.Path != variables.APIPathRegisterUserServer)
		},
		IfTrue: authMiddleware,
	})
	api.Use(rest.DefaultProdStack...)
	router, err := rest.MakeRouter(
		// For accounts, looking up and updating
		rest.Get(variables.APIPathAccountServer, GetAccount),
		rest.Post(variables.APIPathAccountServer, PostAccount),
		// For user actions such as login
		rest.Post(variables.APIPathLoginUserServer, PostLoginUser),
		rest.Get(variables.APIPathRefreshUserServer, PostRefreshUser),
		rest.Post(variables.APIPathRegisterUserServer, PostRegisterUser),
		rest.Get(variables.APIPathUserServer, GetUser),
		rest.Post(variables.APIPathUserServer, PostUser),
	)
	if err != nil {
		log.Fatal(err)
	}
	api.SetApp(router)
	handler := api.MakeHandler()
	return &handler
}
1053317
func WrapHandler(w ...server.HandlerWrapper) Option {
	return func(o *Options) {
		var wrappers []server.Option

		for _, wrap := range w {
			wrappers = append(wrappers, server.WrapHandler(wrap))
		}

		// Init once
		o.Server.Init(wrappers...)
	}
}
198988
func WithHandler(h ...Handler) Option {
	return func(o *Options) {
		o.Handlers = append(o.Handlers, h...)
	}
}
770402
func (r *FlatChain) ServeHTTP(res http.ResponseWriter, req *http.Request) {
	r.Handle(res, req, nil)
}
1181142
func (r *Router) UseHandler(handler http.Handler) *Router {
	r.Route("/*").All(handler.ServeHTTP)
	return r
}
1042208
func (m *Mux) AddHandler(meth, pat string, h http.Handler) error {
	m.mu.Lock()
	defer m.mu.Unlock()
	for _, ph := range m.added[meth] {
		if ph.pat == pat {
			return errors.AlreadyExistsf("handler for %s %q", meth, pat)
		}
	}
	m.added[meth] = append(m.added[meth], patternHandler{pat, h})
	m.recreate()
	return nil
}
419798
func (r *FlatChain) LinkHandleFunc(h http.HandlerFunc) FlatChains {
	fh := FlatChainWrap(h, r.log)
	r.Link(fh)
	return fh
}
825381
func XMLHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/xml")
	fmt.Fprint(w, xmlData)
}
1007428
func (c *Conn) CloseHandler() func(code int, text string) error {
	return c.handleClose
}
1077054
func (l *ConnectionsLimiter) WrapHandle(h http.Handler) {
	l.ConnLimiter.Wrap(h)
}
1334865
func FlatChainHandlerWrap(h http.Handler, lg *log.Logger) FlatChains {
	return NewFlatChain(func(c *Context, nx NextHandler) {
		h.ServeHTTP(c.Res, c.Req)
		nx(c)
	}, lg)
}
320028
func (l *LARS) wrapHandler(h Handler) HandlerFunc {

	switch h := h.(type) {
	case HandlerFunc:
		return h

	case func(Context):
		return h

	case http.Handler, http.HandlerFunc:
		return func(c Context) {

			ctx := c.BaseContext()

			if h.(http.Handler).ServeHTTP(ctx.response, ctx.request); ctx.response.status != http.StatusOK || ctx.response.committed {
				return
			}

			if ctx.index+1 < len(ctx.handlers) {
				c.Next()
			}
		}

	case func(http.ResponseWriter, *http.Request):
		return func(c Context) {

			ctx := c.BaseContext()

			if h(ctx.response, ctx.request); ctx.response.status != http.StatusOK || ctx.response.committed {
				return
			}

			if ctx.index+1 < len(ctx.handlers) {
				c.Next()
			}
		}

	case func(http.ResponseWriter, *http.Request, http.Handler):

		return func(c Context) {
			ctx := c.BaseContext()

			h(ctx.response, ctx.request, NativeChainHandler)
		}

	case func(http.Handler) http.Handler:

		hf := h(NativeChainHandler)

		return func(c Context) {
			ctx := c.BaseContext()

			hf.ServeHTTP(ctx.response, ctx.request)
		}

	default:
		if fn, ok := l.customHandlersFuncs[reflect.TypeOf(h)]; ok {
			return func(c Context) {
				fn(c, h)
			}
		}

		panic("unknown handler")
	}
}
214608
func (c *Context) APIHandler(builder Builder) http.Handler {
	b := builder
	if b == nil {
		b = PassthroughBuilder
	}

	var title string
	sp := c.spec.Spec()
	if sp != nil && sp.Info != nil && sp.Info.Title != "" {
		title = sp.Info.Title
	}

	redocOpts := RedocOpts{
		BasePath: c.BasePath(),
		Title:    title,
	}

	return Spec("", c.spec.Raw(), Redoc(redocOpts, c.RoutesHandler(b)))
}
942958
func makeHandler(binding interface{}, o *Options) martini.Handler {

	return func(context martini.Context, resp http.ResponseWriter, req *http.Request) {
		// Upgrade the request to a websocket connection
		ws, status, err := upgradeRequest(resp, req, o)
		if err != nil {
			resp.WriteHeader(status)
			resp.Write([]byte(err.Error()))
			return
		}

		// Set up the connection
		c := newBinding(binding, ws, o)

		// Set the options for the gorilla websocket package
		c.setSocketOptions()

		// Map the sending and receiving channels
		c.mapChannels(context)

		// Map the Channels <-chan error, <-chan bool and chan<- bool
		c.mapDefaultChannels(context)

		// start the send and receive goroutines
		go c.send()
		go c.recv()
		go waitForDisconnect(c)

		// call the next handler, which must block
		context.Next()
	}
}
1074257
func (s *Server) HTTPHandler() http.Handler {
	s.mu.Lock()
	defer s.mu.Unlock()
	return s.httpHandler
}
1355106
func StaticFileHandler(path string) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		http.ServeFile(w, r, path)
	}
}