func main() { traffic.SetVar("env", "production") router := traffic.New() router.Use(airbrake.New(os.Getenv("AIRBRAKE_API_KEY"))) // Routes router.Get("/", rootHandler) router.Run() }
func init() { // makes logging 'webscale' (ignores them) log.SetOutput(new(mockResponseWriter)) nullLogger = log.New(new(mockResponseWriter), "", 0) martini.Env = martini.Prod traffic.SetVar("env", "bench") beego.RunMode = "prod" }
func BenchmarkPiluTraffic_Simple(b *testing.B) { traffic.SetVar("env", "production") router := traffic.New() router.Get("/action", piluTrafficHandler) rw, r := testRequest("GET", "/action") b.ResetTimer() for i := 0; i < b.N; i++ { router.ServeHTTP(rw, r) } }
func main() { // Setting env to `production`. // Otherwise the ShoeErrors Middleware used in development // will recover from the panics. traffic.SetVar("env", "production") router := traffic.New() router.ErrorHandler = errorHandler router.Get("/", rootHandler) router.Run() }
func init() { // beego sets it to runtime.NumCPU() // Currently none of the contestors does concurrent routing runtime.GOMAXPROCS(1) // makes logging 'webscale' (ignores them) log.SetOutput(new(mockResponseWriter)) nullLogger = log.New(new(mockResponseWriter), "", 0) beego.RunMode = "prod" martini.Env = martini.Prod traffic.SetVar("env", "bench") }
func piluTrafficRouterFor(namespaces []string, resources []string) http.Handler { traffic.SetVar("env", "production") router := traffic.New() for _, ns := range namespaces { for _, res := range resources { router.Get("/"+ns+"/"+res, piluTrafficHandler) router.Post("/"+ns+"/"+res, piluTrafficHandler) router.Get("/"+ns+"/"+res+"/:id", piluTrafficHandler) router.Put("/"+ns+"/"+res+"/:id", piluTrafficHandler) router.Delete("/"+ns+"/"+res+"/:id", piluTrafficHandler) } } return router }
func main() { flag.StringVar(&env, "e", "production", "Environment") flag.StringVar(&host, "b", "127.0.0.1", "Host") flag.IntVar(&port, "p", 7000, "Port") flag.Parse() args := flag.Args() if len(args) != 1 { usage() os.Exit(1) } baseUrl = args[0] if !strings.HasSuffix(baseUrl, "/") { baseUrl = fmt.Sprintf("%s/", baseUrl) } traffic.SetVar("env", env) traffic.SetVar("port", port) traffic.SetVar("host", host) app.Run() }
func BenchmarkPiluTraffic_Middleware(b *testing.B) { traffic.SetVar("env", "production") router := traffic.New() router.Use(&trafficMiddleware{}) router.Use(&trafficMiddleware{}) router.Use(&trafficMiddleware{}) router.Use(&trafficMiddleware{}) router.Use(&trafficMiddleware{}) router.Use(&trafficMiddleware{}) router.Get("/action", piluTrafficHandler) rw, req := testRequest("GET", "/action") b.ResetTimer() for i := 0; i < b.N; i++ { router.ServeHTTP(rw, req) if rw.Code != 200 { panic("no good") } } }
func BenchmarkPiluTraffic_Composite(b *testing.B) { namespaces, resources, requests := resourceSetup(10) traffic.SetVar("env", "production") router := traffic.New() router.Use(&trafficCompositeMiddleware{}) router.Use(&trafficMiddleware{}) router.Use(&trafficMiddleware{}) router.Use(&trafficMiddleware{}) router.Use(&trafficMiddleware{}) router.Use(&trafficMiddleware{}) for _, ns := range namespaces { for _, res := range resources { router.Get("/"+ns+"/"+res, piluTrafficCompositeHandler) router.Post("/"+ns+"/"+res, piluTrafficCompositeHandler) router.Get("/"+ns+"/"+res+"/:id", piluTrafficCompositeHandler) router.Put("/"+ns+"/"+res+"/:id", piluTrafficCompositeHandler) router.Delete("/"+ns+"/"+res+"/:id", piluTrafficCompositeHandler) } } benchmarkRoutes(b, router, requests) }
func startTraffic() { traffic.SetVar("env", "bench") mux := traffic.New() mux.Get("/hello", trafficHandler) http.ListenAndServe(":"+strconv.Itoa(port), mux) }
func initTraffic() { traffic.SetVar("env", "bench") }