mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-18 02:29:41 +02:00
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>
53 lines
1.3 KiB
Go
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,
|
|
},
|
|
})
|
|
}
|