修复格式问题,重构嵌套层数过深的函数

This commit is contained in:
Leonard Wang
2020-05-19 23:46:07 +08:00
parent 5e2687a742
commit b09e54c205
38 changed files with 168 additions and 173 deletions
+5 -5
View File
@@ -8,19 +8,19 @@ import (
"github.com/gin-gonic/gin"
)
//拦截器
// 拦截器
func CasbinHandler() gin.HandlerFunc {
return func(c *gin.Context) {
claims, _ := c.Get("claims")
waitUse := claims.(*request.CustomClaims)
//获取请求的URI
// 获取请求的URI
obj := c.Request.URL.RequestURI()
//获取请求方法
// 获取请求方法
act := c.Request.Method
//获取用户的角色
// 获取用户的角色
sub := waitUse.AuthorityId
e := service.Casbin()
//判断策略中是否存在
// 判断策略中是否存在
if global.GVA_CONFIG.System.Env == "develop" || e.Enforce(sub, obj, act) {
c.Next()
} else {
+1 -1
View File
@@ -15,7 +15,7 @@ func Cors() gin.HandlerFunc {
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type")
c.Header("Access-Control-Allow-Credentials", "true")
//放行所有OPTIONS方法
// 放行所有OPTIONS方法
if method == "OPTIONS" {
c.AbortWithStatus(http.StatusNoContent)
}
+6 -6
View File
@@ -60,10 +60,10 @@ type JWT struct {
}
var (
TokenExpired error = errors.New("Token is expired")
TokenNotValidYet error = errors.New("Token not active yet")
TokenMalformed error = errors.New("That's not even a token")
TokenInvalid error = errors.New("Couldn't handle this token:")
TokenExpired = errors.New("Token is expired")
TokenNotValidYet = errors.New("Token not active yet")
TokenMalformed = errors.New("That's not even a token")
TokenInvalid = errors.New("Couldn't handle this token:")
)
func NewJWT() *JWT {
@@ -72,13 +72,13 @@ func NewJWT() *JWT {
}
}
//创建一个token
// 创建一个token
func (j *JWT) CreateToken(claims request.CustomClaims) (string, error) {
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
return token.SignedString(j.SigningKey)
}
//解析 token
// 解析 token
func (j *JWT) ParseToken(tokenString string) (*request.CustomClaims, error) {
token, err := jwt.ParseWithClaims(tokenString, &request.CustomClaims{}, func(token *jwt.Token) (i interface{}, e error) {
return j.SigningKey, nil
+1 -1
View File
@@ -16,7 +16,7 @@ func LoadTls() gin.HandlerFunc {
})
err := middleware.Process(c.Writer, c.Request)
if err != nil {
//如果出现错误,请不要继续。
// 如果出现错误,请不要继续
fmt.Println(err)
return
}