opengist/internal/web/handler/healthcheck.go
Thomas Miceli d2f6fe1ab8 wip
2024-12-16 01:09:32 +01:00

31 lines
685 B
Go

package handler
import (
"github.com/thomiceli/opengist/internal/db"
"github.com/thomiceli/opengist/internal/web/context"
"time"
)
func Healthcheck(ctx *context.OGContext) error {
// Check database connection
dbOk := "ok"
httpStatus := 200
err := db.Ping()
if err != nil {
dbOk = "ko"
httpStatus = 503
}
return ctx.JSON(httpStatus, map[string]interface{}{
"opengist": "ok",
"database": dbOk,
"time": time.Now().Format(time.RFC3339),
})
}
// Metrics is a dummy handler to satisfy the /metrics endpoint (for Prometheus, Openmetrics, etc.)
// until we have a proper metrics endpoint
func Metrics(ctx *context.OGContext) error {
return ctx.String(200, "")
}