token.go 569 B

123456789101112131415161718192021222324252627
  1. package middleware
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "hongze/hongtao3_watch/controller/resp"
  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. }