From be3d1f044ec463ed2f427fa44574e0528ab916c6 Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Wed, 8 Mar 2017 23:31:03 -0800 Subject: [PATCH] Replace default http router Using julienschmidt/httprouter for future performance enhancements. --- main.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 4662030..17baf5a 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,8 @@ import ( "path" "github.com/fsnotify/fsnotify" + + "github.com/julienschmidt/httprouter" ) const appName = "zap" @@ -17,7 +19,6 @@ const appName = "zap" var version = "develop" func main() { - var ( configName = flag.String("config", "c.yml", "config file") port = flag.Int("port", 8927, "port to bind to") @@ -56,11 +57,12 @@ func main() { } // Set up routes. - http.Handle("/", ctxWrapper{context, IndexHandler}) - http.Handle("/varz", ctxWrapper{context, VarsHandler}) - http.HandleFunc("/healthz", HealthHandler) + router := httprouter.New() + router.Handler("GET", "/", ctxWrapper{context, IndexHandler}) + router.Handler("GET", "/varz", ctxWrapper{context, VarsHandler}) + router.HandlerFunc("GET", "/healthz", HealthHandler) // TODO check for errors - addr in use, sudo issues, etc. fmt.Printf("Launching %s on %s:%d\n", appName, *host, *port) - http.ListenAndServe(fmt.Sprintf("%s:%d", *host, *port), nil) + log.Fatal(http.ListenAndServe(fmt.Sprintf("%s:%d", *host, *port), router)) }