Albirew/mangadex-next
Albirew
/
mangadex-next
Archivé
1
0
Bifurcation 0
Cette révision appartient à :
Hayden Young 2021-03-21 21:05:34 +00:00
Parent e36094d939
révision dcf55c913b
4 fichiers modifiés avec 14 ajouts et 3 suppressions

Voir le fichier

@ -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 {

Voir le fichier

@ -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))
}

Voir le fichier

@ -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
Voir le fichier

@ -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)
})
}