| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package tools
- import (
- "fmt"
- "github.com/gin-gonic/gin"
- jwt "device-manage/pkg/jwtauth"
- )
- func ExtractClaims(c *gin.Context) jwt.MapClaims {
- claims, exists := c.Get(jwt.JwtPayloadKey)
- if !exists {
- return make(jwt.MapClaims)
- }
- return claims.(jwt.MapClaims)
- }
- func GetUserIdUint(c *gin.Context) uint {
- data := ExtractClaims(c)
- if data["identity"] != nil {
- return uint((data["identity"]).(float64))
- }
- fmt.Println(GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetUserId 缺少identity")
- return 0
- }
- func GetUserId(c *gin.Context) int {
- data := ExtractClaims(c)
- if data["identity"] != nil {
- return int((data["identity"]).(float64))
- }
- fmt.Println(GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetUserId 缺少identity")
- return 0
- }
- func GetUserIdStr(c *gin.Context) string {
- data := ExtractClaims(c)
- fmt.Println(">>>>>>>>>>>>")
- fmt.Println(data["identity"])
- if data["identity"] != nil {
- return Int64ToString(int64((data["identity"]).(float64)))
- }
- fmt.Println(GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetUserIdStr 缺少identity")
- return ""
- }
- func GetUserName(c *gin.Context) string {
- data := ExtractClaims(c)
- if data["nice"] != nil {
- return (data["nice"]).(string)
- }
- fmt.Println(GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetUserName 缺少nice")
- return ""
- }
- func GetRoleName(c *gin.Context) string {
- data := ExtractClaims(c)
- if data["rolekey"] != nil {
- return (data["rolekey"]).(string)
- }
- fmt.Println(GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetRoleName 缺少rolekey")
- return ""
- }
- func GetRoleId(c *gin.Context) int {
- data := ExtractClaims(c)
- if data["roleid"] != nil {
- i := int((data["roleid"]).(float64))
- return i
- }
- fmt.Println(GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetRoleId 缺少roleid")
- return 0
- }
|