0
Cette révision appartient à :
Parent
e36094d939
révision
dcf55c913b
4 fichiers modifiés avec 14 ajouts et 3 suppressions
|
@ -10,6 +10,7 @@ import (
|
|||
type HealthController struct{}
|
||||
|
||||
func (h *HealthController) Healthy(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Del("Content-Type")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
|
@ -18,8 +19,9 @@ func (h *HealthController) Metrics(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
output += fmt.Sprintf("mangadex_item_count{type=\"user\"} %v\n", countUsers())
|
||||
|
||||
w.Write([]byte(output))
|
||||
w.Header().Del("Content-Type")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(output))
|
||||
}
|
||||
|
||||
func countUsers() int {
|
||||
|
|
|
@ -25,7 +25,6 @@ func (u *UserController) GetAll(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
w.Header().Add("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(usersJSON)
|
||||
}
|
||||
|
@ -50,7 +49,6 @@ func (u *UserController) GetOne(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
w.Header().Add("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(*userJSON))
|
||||
}
|
||||
|
|
1
main.go
1
main.go
|
@ -38,6 +38,7 @@ func main() {
|
|||
|
||||
r.Use(middlewares.LogMiddleware)
|
||||
r.Use(middlewares.SentryMiddleware)
|
||||
r.Use(middlewares.JSONMiddleware)
|
||||
|
||||
healthRouter := routers.HealthRouter{}
|
||||
healthRouter.RegisterRoutes(r)
|
||||
|
|
10
middlewares/json.go
Fichier normal
10
middlewares/json.go
Fichier normal
|
@ -0,0 +1,10 @@
|
|||
package middlewares
|
||||
|
||||
import "net/http"
|
||||
|
||||
func JSONMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Content-Type", "application/json; charset=utf-8")
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
Référencer dans un nouveau ticket