123456789101112131415161718192021222324252627 |
- package middleware
- import (
- "fmt"
- "github.com/gin-gonic/gin"
- "hongze/hongtao3_watch/controller/resp"
- )
- func Token() gin.HandlerFunc {
- return func(c *gin.Context) {
- token := c.Request.Header.Get("Authorization")
- if token == "" {
- token = c.DefaultQuery("authorization", "")
- if token == "" {
- token = c.DefaultQuery("Authorization", "")
- }
- }
- if token == "" {
- resp.TokenError(nil, "未登录或非法访问", "未登录或非法访问", c)
- c.Abort()
- return
- }
- fmt.Println("token:" + token)
- //c.Set("adminInfo", admin)
- c.Next()
- }
- }
|