4c9ed3c24b
Complete rewrite from Python/FastAPI to Go/Gin: - Go backend: auth (API keys + bcrypt), llama.cpp subprocess manager, hot-swap multi-model, rate limiting, quota system, webhooks - Vue 3 SPA admin panel (src/) with Tailwind CSS - Deployment: Docker multi-stage, docker-compose, nginx, systemd - GORM/SQLite models: ApiKey, Model, UsageLog, Quota, Webhook - REST API: /api/v1/admin/* (keys, models, chat, usage, health) - Embedded frontend via go:embed (build output at web/dist/) Removed legacy Python artifacts (app/, tests/, pyproject.toml, etc.)
59 lines
1.1 KiB
Go
59 lines
1.1 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"gorm.io/gorm"
|
|
|
|
"github.com/llamalink/llamalink/internal/llama"
|
|
)
|
|
|
|
type HealthHandler struct {
|
|
db *gorm.DB
|
|
manager *llama.Manager
|
|
}
|
|
|
|
func NewHealthHandler(db *gorm.DB, manager *llama.Manager) *HealthHandler {
|
|
return &HealthHandler{db: db, manager: manager}
|
|
}
|
|
|
|
func (h *HealthHandler) Health(c *gin.Context) {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"status": "ok",
|
|
})
|
|
}
|
|
|
|
func (h *HealthHandler) Ready(c *gin.Context) {
|
|
// Check DB
|
|
sqlDB, err := h.db.DB()
|
|
if err != nil {
|
|
c.JSON(http.StatusServiceUnavailable, gin.H{
|
|
"status": "not_ready",
|
|
"database": "error",
|
|
})
|
|
return
|
|
}
|
|
if err := sqlDB.Ping(); err != nil {
|
|
c.JSON(http.StatusServiceUnavailable, gin.H{
|
|
"status": "not_ready",
|
|
"database": "unhealthy",
|
|
})
|
|
return
|
|
}
|
|
|
|
// Check model manager
|
|
modelReady := h.manager == nil || h.manager.IsReady()
|
|
modelName := ""
|
|
if h.manager != nil {
|
|
modelName = h.manager.CurrentModel()
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"status": "ready",
|
|
"database": "ok",
|
|
"model_active": modelReady,
|
|
"model_name": modelName,
|
|
})
|
|
}
|