package handler import ( "net/http" "github.com/gin-gonic/gin" "vision-tool/internal/model" "vision-tool/internal/service" ) // AuthHandler HTTP 处理器:进入密钥校验。 type AuthHandler struct { svc *service.AccessService } func NewAuthHandler(svc *service.AccessService) *AuthHandler { return &AuthHandler{svc: svc} } // Verify POST /api/v1/auth/verify — 校验进入密钥(固定密钥,存于数据库) func (h *AuthHandler) Verify(c *gin.Context) { var req struct { Key string `json:"key" binding:"required"` } if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, model.Err(model.CodeBadParam, "请输入进入密钥")) return } if !h.svc.VerifyKey(req.Key) { c.JSON(http.StatusUnauthorized, model.Err(model.CodeUnauthorized, "密钥错误")) return } c.JSON(http.StatusOK, model.OK(gin.H{"ok": true})) }