small fix, don't worry about it

This commit is contained in:
Tomas Dvorak
2026-04-10 12:06:24 +02:00
commit 5c500a72b0
243 changed files with 44176 additions and 0 deletions
@@ -0,0 +1,49 @@
package handlers
import (
"context"
"net/http"
"time"
"github.com/gin-gonic/gin"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/redis/go-redis/v9"
)
type HealthHandler struct {
db *pgxpool.Pool
cache *redis.Client
}
func NewHealthHandler(db *pgxpool.Pool, cache *redis.Client) *HealthHandler {
return &HealthHandler{db: db, cache: cache}
}
func (h *HealthHandler) Live(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"status": "ok", "timestamp": time.Now().UTC()})
}
func (h *HealthHandler) Ready(c *gin.Context) {
ctx, cancel := context.WithTimeout(c.Request.Context(), 2*time.Second)
defer cancel()
health := gin.H{"status": "ready"}
if err := h.db.Ping(ctx); err != nil {
health["status"] = "degraded"
health["postgres"] = err.Error()
c.JSON(http.StatusServiceUnavailable, health)
return
}
if err := h.cache.Ping(ctx).Err(); err != nil {
health["status"] = "degraded"
health["dragonfly"] = err.Error()
c.JSON(http.StatusServiceUnavailable, health)
return
}
health["postgres"] = "ok"
health["dragonfly"] = "ok"
c.JSON(http.StatusOK, health)
}