auth_handler.go 467 B

12345678910111213141516171819202122232425
  1. package handlers
  2. import (
  3. "go-msa-auth/internal/services"
  4. "net/http"
  5. "github.com/gin-gonic/gin"
  6. )
  7. // AuthHandler 处理授权请求
  8. func AuthHandler(c *gin.Context) {
  9. var req services.AuthRequest
  10. // 解析 JSON 请求
  11. if err := c.ShouldBindJSON(&req); err != nil {
  12. c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request format"})
  13. return
  14. }
  15. // 调用业务逻辑
  16. resp := services.HandleAuth(req)
  17. // 返回响应
  18. c.JSON(http.StatusOK, resp)
  19. }