fix: add role limit

This commit is contained in:
fallen-angle
2022-04-27 22:08:02 +08:00
parent fc347a4140
commit 22cb5ec61f
19 changed files with 274 additions and 77 deletions

10
utils/json.go Normal file
View File

@@ -0,0 +1,10 @@
package utils
import (
"encoding/json"
)
func Strcut2Map[S any, T *map[string]interface{} | *[]map[string]interface{}](source S, target T) {
jsonByte, _ := json.Marshal(source)
json.Unmarshal(jsonByte, target)
}

View File

@@ -1,10 +1,13 @@
package utils
import (
"encoding/json"
"fmt"
"nCovTrack-Backend/global"
"nCovTrack-Backend/models"
"time"
"github.com/gin-gonic/gin"
"github.com/golang-jwt/jwt/v4"
)
@@ -81,3 +84,9 @@ func ParseClaims(tokenStr string) jwt.MapClaims {
}
return token.Claims.(jwt.MapClaims)
}
func ClaimsFromHeader(c *gin.Context) models.TokenClaims {
var claims models.TokenClaims
json.Unmarshal([]byte(c.Request.Header.Get("claims")), &claims)
return claims
}