package handler import ( "net/http" "time" "gorm.io/gorm" "github.com/gin-gonic/gin" ) type HealthHandler struct { db *gorm.DB } func NewHealthHandler(db *gorm.DB) *HealthHandler { return &HealthHandler{db: db} } func (h *HealthHandler) Check(c *gin.Context) { sqlDB, err := h.db.DB() if err != nil { c.String(http.StatusInternalServerError, "DB connection error: "+err.Error()) return } if err := sqlDB.Ping(); err != nil { c.String(http.StatusInternalServerError, "DB unreachable: "+err.Error()) return } c.String(http.StatusOK, "Database connected. Server time: %s", time.Now().Format(time.RFC3339)) }