- 新增 docker-compose.yml,按健康检查顺序启动 MySQL 8、Go 后端与 Nginx 前端 - 新增 server/web 多阶段 Dockerfile、nginx 反向代理配置与 .dockerignore - 后端支持 KENAITO_* 环境变量覆盖配置,新增 /health 健康检查接口 - 补充中英文 README 与 Docker 部署文档、.env.example 环境变量模板
28 lines
665 B
Go
28 lines
665 B
Go
package handler
|
|
|
|
import (
|
|
"kenaito-conf/server/internal/dao"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type HealthHandler struct{}
|
|
|
|
func NewHealthHandler() *HealthHandler {
|
|
return &HealthHandler{}
|
|
}
|
|
|
|
// Check 用于容器健康检查,数据库不可用时返回 503
|
|
func (h *HealthHandler) Check(c *gin.Context) {
|
|
if dao.Engine == nil {
|
|
c.JSON(http.StatusServiceUnavailable, gin.H{"status": "error", "message": "database not initialized"})
|
|
return
|
|
}
|
|
if err := dao.Engine.Ping(); err != nil {
|
|
c.JSON(http.StatusServiceUnavailable, gin.H{"status": "error", "message": "database unavailable"})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"status": "ok"})
|
|
}
|