diff options
author | Martin Polden <mpolden@mpolden.no> | 2020-06-19 20:36:17 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2020-06-19 20:36:17 +0200 |
commit | 48ac223f31d4b9bb456f1245529daa52f59a0dab (patch) | |
tree | 1bbbf3c2da6562ed3a0e37140e539348e4460f51 | |
parent | bc32071a962c93bb207e6da466e20d5c8239017c (diff) |
http: Simplify router
-rw-r--r-- | http/http.go | 2 | ||||
-rw-r--r-- | http/router.go | 7 |
2 files changed, 2 insertions, 7 deletions
diff --git a/http/http.go b/http/http.go index d6db139..7eb7184 100644 --- a/http/http.go +++ b/http/http.go @@ -102,7 +102,7 @@ func NewServer(cache *cache.Cache, logger *sql.Logger, sqlCache *sql.Cache, addr } func (s *Server) handler() http.Handler { - r := newRouter() + r := &router{} r.route(http.MethodGet, "/cache/v1/", s.cacheHandler) r.route(http.MethodGet, "/log/v1/", s.logHandler) r.route(http.MethodGet, "/metric/v1/", s.metricHandler) diff --git a/http/router.go b/http/router.go index 6ecc604..27adc33 100644 --- a/http/router.go +++ b/http/router.go @@ -6,7 +6,6 @@ import ( ) type router struct { - mux *http.ServeMux routes []*route } @@ -40,8 +39,6 @@ func (fn appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } -func newRouter() *router { return &router{mux: http.DefaultServeMux} } - func notFoundHandler(w http.ResponseWriter, r *http.Request) (interface{}, *httpError) { return nil, &httpError{ Status: http.StatusNotFound, @@ -60,7 +57,7 @@ func (r *router) route(method, path string, handler appHandler) *route { } func (r *router) handler() http.Handler { - appHandler := appHandler(func(w http.ResponseWriter, req *http.Request) (interface{}, *httpError) { + return appHandler(func(w http.ResponseWriter, req *http.Request) (interface{}, *httpError) { for _, route := range r.routes { if route.match(req) { return route.handler(w, req) @@ -68,8 +65,6 @@ 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 { |