Albirew/mangadex-next
Albirew
/
mangadex-next
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2024-03-02. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
mangadex-next/controllers/health.go

35 lignes
712 B
Go

package controllers
import (
"fmt"
"net/http"
"github.com/hbjydev/mangadex-next/database"
)
type HealthController struct{}
func (h *HealthController) Healthy(w http.ResponseWriter, r *http.Request) {
w.Header().Del("Content-Type")
w.WriteHeader(http.StatusOK)
}
func (h *HealthController) Metrics(w http.ResponseWriter, r *http.Request) {
var output string
output += fmt.Sprintf("mangadex_item_count{type=\"user\"} %v\n", countUsers())
w.Header().Del("Content-Type")
w.WriteHeader(http.StatusOK)
w.Write([]byte(output))
}
func countUsers() int {
row := database.DB.QueryRow("SELECT count(id) FROM users")
var count int
if err := row.Scan(&count); err != nil {
return -1
}
return count
}