Add /health and /ready for transcoder

This commit is contained in:
Zoe Roux
2025-11-09 19:14:13 +01:00
parent 8f0fb42b47
commit 563ae85db1
6 changed files with 55 additions and 14 deletions
+40
View File
@@ -0,0 +1,40 @@
package api
import (
"github.com/jackc/pgx/v5/pgxpool"
"github.com/labstack/echo/v4"
)
type health struct {
db *pgxpool.Pool
}
func RegisterHealthHandlers(e *echo.Group, db *pgxpool.Pool) {
h := health{db}
e.GET("/health", h.CheckHealth)
e.GET("/ready", h.CheckReady)
}
func (h *health) CheckHealth(c echo.Context) error {
return c.JSON(200, struct {
Status string `json:"status"`
}{Status: "healthy"})
}
func (h *health) CheckReady(c echo.Context) error {
_, err := h.db.Exec(c.Request().Context(), "select 1")
status := "healthy"
db := "healthy"
ret := 200
if err != nil {
status = "unhealthy"
ret = 500
db = err.Error()
}
return c.JSON(ret, struct {
Status string `json:"status"`
Database string `json:"database"`
}{Status: status, Database: db})
}