managarten/services/mana-search/internal/handler/health.go
Till JS d3d11e661d feat(apps): create Hono compute servers for Traces, Planta, NutriPhi
Add lightweight Hono + Bun servers for server-only compute endpoints.
CRUD is handled by mana-sync, these handle AI + file upload only.

Traces: AI guide generation, location sync (Port 3026)
Planta: Photo upload (S3), AI plant analysis (Port 3022)
NutriPhi: AI meal analysis (photo+text), recommendations (Port 3023)

Each uses @manacore/shared-hono for auth/health/errors. ~100-200 LOC.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 16:16:57 +01:00

53 lines
1.3 KiB
Go

package handler
import (
"net/http"
"github.com/manacore/shared-go/httputil"
"time"
"github.com/manacore/mana-search/internal/cache"
"github.com/manacore/mana-search/internal/search"
)
type HealthHandler struct {
provider *search.SearxngProvider
cache *cache.Cache
startTime time.Time
}
func NewHealthHandler(provider *search.SearxngProvider, c *cache.Cache) *HealthHandler {
return &HealthHandler{
provider: provider,
cache: c,
startTime: time.Now(),
}
}
// Health handles GET /health
func (h *HealthHandler) Health(w http.ResponseWriter, r *http.Request) {
sxStatus, sxLatency := h.provider.HealthCheck(r.Context())
redisHealth := h.cache.HealthCheck(r.Context())
overall := "ok"
if sxStatus == "error" && redisHealth.Status == "error" {
overall = "error"
} else if sxStatus == "error" || redisHealth.Status == "error" || redisHealth.Status == "disabled" {
overall = "degraded"
}
httputil.WriteJSON(w, http.StatusOK, map[string]any{
"status": overall,
"service": "mana-search",
"version": "1.0.0",
"uptime": time.Since(h.startTime).Seconds(),
"timestamp": time.Now().UTC().Format(time.RFC3339),
"components": map[string]any{
"searxng": map[string]any{
"status": sxStatus,
"latency": sxLatency,
},
"redis": redisHealth,
},
})
}