aboutsummaryrefslogtreecommitdiffstats
path: root/http
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2019-12-31 12:17:11 +0100
committerMartin Polden <mpolden@mpolden.no>2019-12-31 13:49:02 +0100
commit962b8ed95a9bfebf3f7fd35307d4e9484fda369a (patch)
tree248ae5697be31b8f1c728a56d0a7478984ce4fb4 /http
parent50159f241973d24e48b2d2c3ae5e353d9c64eb4d (diff)
Add pprof handlers
Diffstat (limited to 'http')
-rw-r--r--http/http.go1
-rw-r--r--http/router.go7
2 files changed, 6 insertions, 2 deletions
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 {