12345678910111213141516171819202122232425 |
- package middleware
- import (
- "AIT/common"
- "AIT/response"
- "github.com/gin-gonic/gin"
- )
- func JwtAuth() gin.HandlerFunc {
- return func(context *gin.Context) {
- token := context.Request.Header.Get("token")
- if token == "" {
- response.Failed("非法访问", context)
- context.Abort()
- return
- }
- if err := common.VerifyToken(token); err != nil {
- response.Failed("登录已过期,请重新登录", context)
- context.Abort()
- return
- }
- context.Next()
- }
- }
|