first commit

This commit is contained in:
Beyhan Ogur
2026-05-11 15:08:50 +03:00
commit a408821410
47 changed files with 4670 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
package handlers
import (
"github.com/gofiber/fiber/v3"
"gorm.io/gorm"
"optoant/config"
)
// HealthResponse is the structure returned by the /health endpoint.
type HealthResponse struct {
Status string `json:"status"`
Database string `json:"database"`
Config struct {
OpenAIBackend string `json:"openai_backend"`
Port string `json:"port"`
} `json:"config"`
}
// HealthHandler returns service status and basic config info.
// @Summary Health check
// @Description Returns service health status, database connectivity, and active configuration.
// @Tags health
// @Produce json
// @Success 200 {object} HealthResponse
// @Router /health [get]
func HealthHandler(cfg *config.Config, db *gorm.DB) fiber.Handler {
return func(c fiber.Ctx) error {
resp := HealthResponse{
Status: "ok",
}
resp.Config.OpenAIBackend = cfg.OpenAIBackend
resp.Config.Port = cfg.Port
// Check DB connectivity
if db != nil {
sqlDB, err := db.DB()
if err != nil || sqlDB.Ping() != nil {
resp.Database = "unreachable"
} else {
resp.Database = "ok"
}
} else {
resp.Database = "disabled"
}
return c.JSON(resp)
}
}