Skip to content

Commit

Permalink
Replace default http router
Browse files Browse the repository at this point in the history
Using julienschmidt/httprouter for future performance enhancements.
  • Loading branch information
issmirnov authored Mar 9, 2017
1 parent 2b44cdf commit be3d1f0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"path"

"github.com/fsnotify/fsnotify"

"github.com/julienschmidt/httprouter"
)

const appName = "zap"
Expand All @@ -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")
Expand Down Expand Up @@ -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))
}

0 comments on commit be3d1f0

Please sign in to comment.