Skip to content

Commit

Permalink
Merge pull request #6 from issmirnov/router
Browse files Browse the repository at this point in the history
Replace default http router. Performance gains are 23%.
  • Loading branch information
issmirnov committed Mar 11, 2017
2 parents 2b44cdf + be3d1f0 commit f815861
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 f815861

Please sign in to comment.