29 lines
466 B
Go
29 lines
466 B
Go
|
|
package handler
|
||
|
|
|
||
|
|
import (
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
||
|
|
)
|
||
|
|
|
||
|
|
type HealthHandler struct {
|
||
|
|
pool *pgxpool.Pool
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewHealthHandler(pool *pgxpool.Pool) *HealthHandler {
|
||
|
|
return &HealthHandler{pool: pool}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (h *HealthHandler) Health(c *gin.Context) {
|
||
|
|
dbOK := h.pool.Ping(c.Request.Context()) == nil
|
||
|
|
|
||
|
|
status := "healthy"
|
||
|
|
if !dbOK {
|
||
|
|
status = "degraded"
|
||
|
|
}
|
||
|
|
|
||
|
|
c.JSON(200, gin.H{
|
||
|
|
"status": status,
|
||
|
|
"database": dbOK,
|
||
|
|
})
|
||
|
|
}
|