From 962b8ed95a9bfebf3f7fd35307d4e9484fda369a Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Tue, 31 Dec 2019 12:17:11 +0100 Subject: Add pprof handlers --- http/http.go | 1 + http/router.go | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'http') diff --git a/http/http.go b/http/http.go index 7fdd16a..ac2e9b0 100644 --- a/http/http.go +++ b/http/http.go @@ -4,6 +4,7 @@ import ( "context" "net" "net/http" + _ "net/http/pprof" // Registers debug handlers as a side effect. "strconv" "time" diff --git a/http/router.go b/http/router.go index e7087f7..6ecc604 100644 --- a/http/router.go +++ b/http/router.go @@ -6,6 +6,7 @@ import ( ) type router struct { + mux *http.ServeMux routes []*route } @@ -39,7 +40,7 @@ func (fn appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } -func newRouter() *router { return &router{} } +func newRouter() *router { return &router{mux: http.DefaultServeMux} } func notFoundHandler(w http.ResponseWriter, r *http.Request) (interface{}, *httpError) { return nil, &httpError{ @@ -59,7 +60,7 @@ func (r *router) route(method, path string, handler appHandler) *route { } func (r *router) handler() http.Handler { - return appHandler(func(w http.ResponseWriter, req *http.Request) (interface{}, *httpError) { + appHandler := appHandler(func(w http.ResponseWriter, req *http.Request) (interface{}, *httpError) { for _, route := range r.routes { if route.match(req) { return route.handler(w, req) @@ -67,6 +68,8 @@ func (r *router) handler() http.Handler { } return notFoundHandler(w, req) }) + r.mux.Handle("/", appHandler) + return r.mux } func (r *route) match(req *http.Request) bool { -- cgit v1.2.3