Jwt.go 511 Bytes
Newer Older
彭芳 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
package mid

import (
	"net/http"

	"github.com/gin-gonic/gin"

	"demo/internal/util"
)

type Jwt struct {
}

func (p *Jwt) CheckToken(c *gin.Context) {
	headerToken := c.Request.Header.Get(util.Token)
	if util.DefaultToken != headerToken {
		c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{
			util.RequestKey: c.GetString(util.RequestKey),
			"code":          http.StatusUnauthorized,
			"message":       "token 校验失败",
		})
		return
	}
	c.Set(util.CustomerId, util.DefaultCustomerId)
	c.Next()
}