// Handler returns an http.Handler for the API.
Handler returns an http.Handler for the API.
// Handler returns an http . Handler for the API .
func Handler() error {
	db := db()
	r := mux.NewRouter()
	statsMiddleware := stats.New()
	r.HandleFunc("/stats", newAdminHandler(statsMiddleware).ServeHTTP)
	n := negroni.New()
	recovery := negroni.NewRecovery()
	recovery.PrintStack = false
	n.Use(recovery)
	if viper.GetBool("log.requests") {
		n.Use(negronilogrus.NewCustomMiddleware(utils.GetLogLevel(), utils.GetLogFormatter(), "requests"))
	}
	n.Use(statsMiddleware)
	n.Use(negroni.HandlerFunc(func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
		utils.Metrics().Incr("request.incoming", nil, 1)
		utils.Metrics().Gauge("request.active", 1, nil, 1)
		next(rw, r)
	}))
	if viper.GetBool("correlation.enable") {
		n.Use(negroni.HandlerFunc(correlationMiddleware(viper.GetStringMap("correlation"))))
	}
	n.Use(negroni.HandlerFunc(validate(viper.GetInt("local.skew"))))
	algorithm := viper.Get("local.algorithm")
	n.Use(negroni.HandlerFunc(digest(algorithm.(crypto.Hash))))
	n.Use(negroni.HandlerFunc(authorization))
	n.Use(negroni.HandlerFunc(signature(db, algorithm.(crypto.Hash))))
	forwardConn := fmt.Sprintf("%s%s:%d", viper.GetString("service.protocol"), viper.GetString("service.hostname"), viper.GetInt("service.port"))
	r.PathPrefix("/").Handler(proxy(forwardConn))
	n.UseHandler(r)
	conn := fmt.Sprintf("%s:%d", viper.GetString("listen.bind"), viper.GetInt("listen.port"))
	log.Infof("Listening on %s", conn)
	return server(conn, n).ListenAndServe()
}
func Handler ( ) error { db := db ( ) r := mux . NewRouter ( ) statsMiddleware := stats . New ( ) r . HandleFunc ( " " , newAdminHandler ( statsMiddleware ) . ServeHTTP ) n := negroni . New ( ) recovery := negroni . NewRecovery ( ) recovery . PrintStack = false n . Use ( recovery ) if viper . GetBool ( " " ) { n . Use ( negronilogrus . NewCustomMiddleware ( utils . GetLogLevel ( ) , utils . GetLogFormatter ( ) , " " ) ) } n . Use ( statsMiddleware ) n . Use ( negroni . HandlerFunc ( func ( rw http . ResponseWriter , r * http . Request , next http . HandlerFunc ) { utils . Metrics ( ) . Incr ( " " , nil , 1 ) utils . Metrics ( ) . Gauge ( " " , 1 , nil , 1 ) next ( rw , r ) } ) ) if viper . GetBool ( " " ) { n . Use ( negroni . HandlerFunc ( correlationMiddleware ( viper . GetStringMap ( " " ) ) ) ) } n . Use ( negroni . HandlerFunc ( validate ( viper . GetInt ( " " ) ) ) ) algorithm := viper . Get ( " " ) n . Use ( negroni . HandlerFunc ( digest ( algorithm . ( crypto . Hash ) ) ) ) n . Use ( negroni . HandlerFunc ( authorization ) ) n . Use ( negroni . HandlerFunc ( signature ( db , algorithm . ( crypto . Hash ) ) ) ) forwardConn := fmt . Sprintf ( " " , viper . GetString ( " " ) , viper . GetString ( " " ) , viper . GetInt ( " " ) ) r . PathPrefix ( " " ) . Handler ( proxy ( forwardConn ) ) n . UseHandler ( r ) conn := fmt . Sprintf ( " " , viper . GetString ( " " ) , viper . GetInt ( " " ) ) log . Infof ( " " , conn ) return server ( conn , n ) . ListenAndServe ( ) }
Handler returns an http.Handler for the API.
Handler returns an http . Handler for the API .
// Add middleware handlers // Add recovery handler that logs // Collect some metrics about incoming and active requests // Correlation id middleware // Validate headers // Validate the digest header // All checks passed, forward the request // Set up connection // Bombs away!