// NewHTTPHandler returns a new HTTP handler our svc1.
544487
func NewHTTPHandler(tracer opentracing.Tracer, service Service) http.Handler {
	// Create our HTTP Service.
	svc := &httpService{service: service}

	// Create the mux.
	mux := http.NewServeMux()

	// Create the Concat handler.
	var concatHandler http.Handler
	concatHandler = http.HandlerFunc(svc.concatHandler)

	// Wrap the Concat handler with our tracing middleware.
	concatHandler = middleware.FromHTTPRequest(tracer, "Concat")(concatHandler)

	// Create the Sum handler.
	var sumHandler http.Handler
	sumHandler = http.HandlerFunc(svc.sumHandler)

	// Wrap the Sum handler with our tracing middleware.
	sumHandler = middleware.FromHTTPRequest(tracer, "Sum")(sumHandler)

	// Wire up the mux.
	mux.Handle("/concat/", concatHandler)
	mux.Handle("/sum/", sumHandler)

	// Return the mux.
	return mux
}
358328
func NewHandler(proxy bool, peers []string) *Handler {
	r := httprouter.New()

	h := &Handler{Handler: r}
	h.Shutdown.Store(false)

	h.Peers = peers
	h.Proxy.Store(proxy)

	if os.Getenv("DEBUG") != "" {
		h.Handler = hh.ContextInjector("discoverd", hh.NewRequestLoggerCustom(h.Handler, loggerFn))
	}

	r.HandlerFunc("GET", status.Path, status.HealthyHandler.ServeHTTP)

	r.PUT("/services/:service", h.servePutService)
	r.DELETE("/services/:service", h.serveDeleteService)
	r.GET("/services/:service", h.serveGetService)

	r.PUT("/services/:service/meta", h.servePutServiceMeta)
	r.GET("/services/:service/meta", h.serveGetServiceMeta)

	r.PUT("/services/:service/instances/:instance_id", h.servePutInstance)
	r.DELETE("/services/:service/instances/:instance_id", h.serveDeleteInstance)
	r.GET("/services/:service/instances", h.serveGetInstances)

	r.PUT("/services/:service/leader", h.servePutLeader)
	r.GET("/services/:service/leader", h.serveGetLeader)

	r.GET("/raft/leader", h.serveGetRaftLeader)
	r.GET("/raft/peers", h.serveGetRaftPeers)
	r.PUT("/raft/peers/:peer", h.servePutRaftPeer)
	r.DELETE("/raft/peers/:peer", h.serveDeleteRaftPeer)
	r.POST("/raft/promote", h.servePromote)
	r.POST("/raft/demote", h.serveDemote)

	r.GET("/ping", h.servePing)

	r.POST("/shutdown", h.serveShutdown)
	return h
}
1106143
func NewProtoHandler(b *ProtoBackend) *ProtoHandler {
	h := &ProtoHandler{
		Router:       NewRouter(),
		Logger:       b.Logger,
		ProtoService: b.ProtoService,
		LabelService: b.LabelService,
	}

	h.HandlerFunc("GET", protosPath, h.handleGetProtos)
	h.HandlerFunc("POST", protosDashboardsPath, h.handlePostProtosDashboards)

	return h
}
1129498
func NewHandler(n *centrifuge.Node, c Config) *Handler {
	return &Handler{
		node:   n,
		config: c,
		api:    newAPIExecutor(n, "http"),
	}
}
706144
func (r *Registry) HTTPHandler() http.Handler {
	opts := promhttp.HandlerOpts{
		ErrorLog: promLogger{r: r},
		// TODO(mr): decide if we want to set MaxRequestsInFlight or Timeout.
	}
	return promhttp.HandlerFor(r.Registry, opts)
}
1097468
func NewQueryHandler(handler QueryHandler) http.Handler {
	return handlerFunc(func(ctx context.Context, enc *objconv.StreamEncoder, dec *objconv.Decoder) error {
		req := queryRequest{}
		res := queryResponse{enc: enc}

		if err := dec.Decode(&req); err != nil {
			return err
		}

		if err := handler.ServeQuery(ctx, &res, &QueryRequest{
			From:          req.Range.From,
			To:            req.Range.To,
			Interval:      req.Interval,
			Targets:       req.Targets,
			MaxDataPoints: req.MaxDataPoints,
		}); err != nil {
			return err
		}

		return res.close()
	})
}
1032207
func NewHandler(plugin Plugin) *Handler {
	h := &Handler{plugin, sdk.NewHandler(manifest)}
	h.initMux()
	return h
}
487198
func NewHandler(config HandlerConfig) (http.Handler, error) {
	if config.GetDeviceKeysByDevEUIFunc == nil {
		return nil, errors.New("backend/joinserver: GetDeviceKeysFunc must not be nil")
	}

	h := handler{
		config: config,
		log:    config.Logger,
	}

	if h.log == nil {
		h.log = &log.Logger{
			Out: ioutil.Discard,
		}
	}

	if h.config.GetKEKByLabelFunc == nil {
		h.log.Warning("backend/joinserver: get kek by label function is not set")

		h.config.GetKEKByLabelFunc = func(label string) ([]byte, error) {
			return nil, nil
		}
	}

	if h.config.GetASKEKLabelByDevEUIFunc == nil {
		h.log.Warning("backend/joinserver: get application-server kek by deveui function is not set")

		h.config.GetASKEKLabelByDevEUIFunc = func(devEUI lorawan.EUI64) (string, error) {
			return "", nil
		}
	}

	return &h, nil
}
455303
func NewHandler(Next httpserver.Handler, config *Config) *Handler {
	return &Handler{
		Config:   config,
		Cache:    NewHTTPCache(config.CacheKeyTemplate),
		URLLocks: NewURLLock(),
		Next:     Next,
	}
}
213935
func NewHandler(
	connections chan<- net.Conn,
	abort <-chan struct{},
) *Handler {
	return &Handler{
		connections: connections,
		abort:       abort,
	}
}
240062
func NewHandler(h interface{}) (handler, error) {
	switch v := h.(type) {
	case fullHandler:
		return &FullHandler{handler: v}, nil
	case handler:
		return v, nil
	default:
		return nil, fmt.Errorf("%v does not implement the handler interface", v)
	}
}
92857
func NewHandler(c Config) func(http.Handler) http.Handler {
	if c.Output == nil {
		c.Output = NewOutputChannel(NewConsoleOutput())
	}
	return func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			var l Logger
			if r != nil {
				l = New(c)
				r = r.WithContext(NewContext(r.Context(), l))
			}
			next.ServeHTTP(w, r)
			if l, ok := l.(*logger); ok {
				l.close()
			}
		})
	}
}
347130
func NewRouter(routes Routes, handlers Handlers) (http.Handler, error) {
	p := pat.New()

	for _, route := range routes {
		handler, ok := handlers[route.Name]
		if !ok {
			return nil, fmt.Errorf("missing handler %s", route.Name)
		}

		switch method := strings.ToUpper(route.Method); method {
		case GET, HEAD, POST, PUT, PATCH, DELETE, CONNECT, OPTIONS, TRACE:
			p.Add(method, route.Path, handler)
		default:
			return nil, fmt.Errorf("invalid verb: %s", route.Method)
		}
	}

	return p, nil
}
214208
func NewHTTPServer(cors []string, vhosts []string, timeouts HTTPTimeouts, srv http.Handler) *http.Server {
	// Wrap the CORS-handler within a host-handler
	handler := newCorsHandler(srv, cors)
	handler = newVHostHandler(vhosts, handler)

	// Make sure timeout values are meaningful
	if timeouts.ReadTimeout < time.Second {
		log.Warn("Sanitizing invalid HTTP read timeout", "provided", timeouts.ReadTimeout, "updated", DefaultHTTPTimeouts.ReadTimeout)
		timeouts.ReadTimeout = DefaultHTTPTimeouts.ReadTimeout
	}
	if timeouts.WriteTimeout < time.Second {
		log.Warn("Sanitizing invalid HTTP write timeout", "provided", timeouts.WriteTimeout, "updated", DefaultHTTPTimeouts.WriteTimeout)
		timeouts.WriteTimeout = DefaultHTTPTimeouts.WriteTimeout
	}
	if timeouts.IdleTimeout < time.Second {
		log.Warn("Sanitizing invalid HTTP idle timeout", "provided", timeouts.IdleTimeout, "updated", DefaultHTTPTimeouts.IdleTimeout)
		timeouts.IdleTimeout = DefaultHTTPTimeouts.IdleTimeout
	}
	// Bundle and start the HTTP server
	return &http.Server{
		Handler:      handler,
		ReadTimeout:  timeouts.ReadTimeout,
		WriteTimeout: timeouts.WriteTimeout,
		IdleTimeout:  timeouts.IdleTimeout,
	}
}
730552
func NewFieldHandler(next http.Handler, name string, value string, applyFn FieldApply) http.Handler {
	return &FieldHandler{next: next, name: name, value: value, applyFn: applyFn}
}
415317
func RequestHandler(name string) func(next xhandler.HandlerC) xhandler.HandlerC {
	return func(next xhandler.HandlerC) xhandler.HandlerC {
		return xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
			FromContext(ctx).SetField(name, r.Method+" "+r.URL.String())
			next.ServeHTTPC(ctx, w, r)
		})
	}
}
150467
func NewHandler(cfg Config) (*Handler, error) {
	if err := cfg.CheckAndSetDefaults(); err != nil {
		return nil, trace.Wrap(err)
	}

	h := &Handler{
		Entry: log.WithFields(log.Fields{
			trace.Component: teleport.Component(teleport.SchemeS3),
		}),
		Config:     cfg,
		uploader:   s3manager.NewUploader(cfg.Session),
		downloader: s3manager.NewDownloader(cfg.Session),
		client:     s3.New(cfg.Session),
	}
	start := time.Now()
	h.Infof("Setting up bucket %q, sessions path %q in region %q.", h.Bucket, h.Path, h.Region)
	if err := h.ensureBucket(); err != nil {
		return nil, trace.Wrap(err)
	}
	h.WithFields(log.Fields{"duration": time.Now().Sub(start)}).Infof("Setup bucket %q completed.", h.Bucket)
	return h, nil
}