opengist/internal/web/handlers/healthcheck.go

32 lines
682 B
Go
Raw Normal View History

2025-01-06 13:18:31 +00:00
package handlers
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"
)
2025-01-06 13:18:31 +00:00
func Healthcheck(ctx *context.Context) 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
2025-01-06 13:18:31 +00:00
func Metrics(ctx *context.Context) error {
2024-09-11 23:45:30 +00:00
return ctx.String(200, "")
}