aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 {