From 60536189d43f24453b9d10ca8d979766498c434f Mon Sep 17 00:00:00 2001 From: mls-361 Date: Sun, 9 May 2021 14:45:13 +0200 Subject: [PATCH] =?UTF-8?q?En=20cours=20de=20d=C3=A9veloppement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/api/api.go | 1 - internal/router/router.go | 19 ++++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/internal/api/api.go b/internal/api/api.go index 89f4034..d56216c 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -89,7 +89,6 @@ func Build(ccs *components.Components) { api := newAPI(ccs) router := ccs.Router - //router.Get("/debug", expvar.Handler()) //AFINIR router.Get("/status", api.middleware(func(r *jsonapi.Request) { r.RenderOK() })) diff --git a/internal/router/router.go b/internal/router/router.go index 591f863..95549ea 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -7,6 +7,7 @@ package router import ( + "expvar" "net/http" "forge.chapril.org/mls-361/jsonapi" @@ -34,6 +35,14 @@ func Build(_ *components.Components) components.Router { rw.WriteHeader(http.StatusInternalServerError) } + cr.mux.Handle( + http.MethodGet, + "/debug", + func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { + expvar.Handler().ServeHTTP(w, r) + }, + ) + return cr } @@ -47,10 +56,14 @@ func (cr *router) handle(method string, path string, handler jsonapi.Handler) { method, path, func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { - mp := make(map[string]string) + var mp map[string]string + + if len(ps) > 0 { + mp = make(map[string]string, len(ps)) - for _, p := range ps { - mp[p.Key] = p.Value + for _, p := range ps { + mp[p.Key] = p.Value + } } handler.Serve(jsonapi.NewRequest(r, w, mp))