func BenchmarkHttpRouter(b *testing.B) { b.Skip("skip for now") router := httprouter.New() handler := func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {} router.POST("/topics/:topic/:ver", handler) router.POST("/ws/topics/:topic/:ver", handler) router.GET("/ver", handler) router.GET("/help", handler) router.GET("/stat", handler) router.GET("/ping", handler) router.GET("/clusters", handler) request, _ := http.NewRequest("POST", "/topics/anything/v1", nil) for i := 0; i < b.N; i++ { router.ServeHTTP(nil, request) } }
func newWebServer(name string, httpAddr, httpsAddr string, maxClients int, idleTimeout time.Duration, gw *Gateway) *webServer { this := &webServer{ name: name, gw: gw, maxClients: maxClients, router: httprouter.New(), closed: make(chan struct{}), } if Options.EnableHttpPanicRecover { this.router.PanicHandler = func(w http.ResponseWriter, r *http.Request, err interface{}) { log.Error("PANIC %s %s(%s) %s %s: %+v", this.name, r.RemoteAddr, getHttpRemoteIp(r), r.Method, r.RequestURI, err) writeServerError(w, http.StatusText(http.StatusInternalServerError)) } } if httpAddr != "" { this.httpServer = &http.Server{ Addr: httpAddr, Handler: this.router, ReadTimeout: idleTimeout, WriteTimeout: Options.HttpWriteTimeout, MaxHeaderBytes: Options.HttpHeaderMaxBytes, } } if httpsAddr != "" { this.httpsServer = &http.Server{ Addr: httpsAddr, Handler: this.router, ReadTimeout: idleTimeout, WriteTimeout: Options.HttpWriteTimeout, MaxHeaderBytes: Options.HttpHeaderMaxBytes, } } return this }