token.go 568 B

12345678910111213141516171819202122232425262728
  1. package middleware
  2. import (
  3. "fmt"
  4. "hongze/hongqi_watch/controller/resp"
  5. "github.com/gin-gonic/gin"
  6. )
  7. func Token() gin.HandlerFunc {
  8. return func(c *gin.Context) {
  9. token := c.Request.Header.Get("Authorization")
  10. if token == "" {
  11. token = c.DefaultQuery("authorization", "")
  12. if token == "" {
  13. token = c.DefaultQuery("Authorization", "")
  14. }
  15. }
  16. if token == "" {
  17. resp.TokenError(nil, "未登录或非法访问", "未登录或非法访问", c)
  18. c.Abort()
  19. return
  20. }
  21. fmt.Println("token:" + token)
  22. //c.Set("adminInfo", admin)
  23. c.Next()
  24. }
  25. }