Browse Source

En cours de développement

master
mls-361 2 months ago
parent
commit
60536189d4
  1. 1
      internal/api/api.go
  2. 19
      internal/router/router.go

1
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()
}))

19
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))

Loading…
Cancel
Save