Example #1
0
func main() {
	settings.Init()
	jobRunner.InitialiseJobs()
	router := routers.InitRoutes()
	n := negroni.Classic()
	n.Use(xrequestid.New(16))
	n.Use(negroni.HandlerFunc(func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
		rw.Header().Set(xrequestid.DefaultHeaderKey, r.Header.Get(xrequestid.DefaultHeaderKey))
		next(rw, r)
	}))

	n.UseHandler(router)
	http.ListenAndServe(":5000", n)
}
Example #2
0
func newServerStack(engine *engine.Engine) *negroni.Negroni {
	context := handlers.NewContext(engine)

	router := mux.NewRouter().StrictSlash(true)
	router.HandleFunc("/", context.IndexHandler).Methods("GET")
	router.HandleFunc("/execute", context.ExecuteHandler).Methods("POST")
	router.HandleFunc("/executews", context.ExecuteWSHandler).Methods("GET")
	router.HandleFunc("/info", context.InfoHandler).Methods("GET")

	server := negroni.New(xrequestid.New(16),
		context,
		negronilogrus.NewCustomMiddleware(logrus.InfoLevel, &logrus.JSONFormatter{}, "straitjacket"),
		cors.Default(),
		negroni.NewStatic(http.Dir("public")))
	server.UseHandler(router)
	return server
}
Example #3
0
func initialize() *negroni.Negroni {
	vabanstats := stats.New()
	n := negroni.New(
		negroni.NewRecovery(),
		NewLogger(),
		xrequestid.New(8),
	)
	router := httprouter.New()
	router.GET("/", func(w http.ResponseWriter, req *http.Request, _ httprouter.Params) {
		stats := vabanstats.Data()
		r.JSON(w, http.StatusOK, stats)
	})
	router.GET("/v1/services", GetServices)
	router.GET("/v1/service/:service", GetService)
	router.GET("/v1/service/:service/ping", GetPing)
	router.GET("/v1/service/:service/health", GetHealth)
	router.GET("/v1/service/:service/health/:backend", GetHealth)
	router.POST("/v1/service/:service/health/:backend", PostHealth)
	router.POST("/v1/service/:service/ban", PostBan)
	// add router and clear mux.context values at the end of request life-times
	n.UseHandler(router)
	return n
}