opengist/internal/web/handler/healthcheck.go

32 lines
685 B
Go
Raw Normal View History

2024-12-03 01:18:04 +00:00
package handler
2023-12-16 00:27:00 +00:00
import (
"github.com/thomiceli/opengist/internal/db"
2024-12-03 01:18:04 +00:00
"github.com/thomiceli/opengist/internal/web/context"
2023-12-16 00:27:00 +00:00
"time"
)
2024-12-16 00:09:32 +00:00
func Healthcheck(ctx *context.OGContext) error {
2023-12-16 00:27:00 +00:00
// Check database connection
dbOk := "ok"
httpStatus := 200
err := db.Ping()
if err != nil {
dbOk = "ko"
httpStatus = 503
}
return ctx.JSON(httpStatus, map[string]interface{}{
2024-01-04 15:45:57 +00:00
"opengist": "ok",
2023-12-16 00:27:00 +00:00
"database": dbOk,
"time": time.Now().Format(time.RFC3339),
})
}
2024-09-11 23:45:30 +00:00
2024-12-16 00:09:32 +00:00
// Metrics is a dummy handler to satisfy the /metrics endpoint (for Prometheus, Openmetrics, etc.)
2024-09-11 23:45:30 +00:00
// until we have a proper metrics endpoint
2024-12-16 00:09:32 +00:00
func Metrics(ctx *context.OGContext) error {
2024-09-11 23:45:30 +00:00
return ctx.String(200, "")
}