1 Star 0 Fork 0

青榄/goadmincore

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
user.go 2.53 KB
Copy Edit Raw Blame History
wangxinghong authored 2021-10-06 00:02 +08:00 . 修改mod
package user
import (
"fmt"
"github.com/gin-gonic/gin"
"gitee.com/qlanwl/goadmincore/sdk/pkg"
jwt "gitee.com/qlanwl/goadmincore/sdk/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 Get(c *gin.Context, key string) interface{} {
data := ExtractClaims(c)
if data[key] != nil {
return data[key]
}
fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " Get 缺少 " + key)
return nil
}
func GetUserId(c *gin.Context) int {
data := ExtractClaims(c)
if data["identity"] != nil {
return int((data["identity"]).(float64))
}
fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetUserId 缺少 identity")
return 0
}
func GetUserIdStr(c *gin.Context) string {
data := ExtractClaims(c)
if data["identity"] != nil {
return pkg.Int64ToString(int64((data["identity"]).(float64)))
}
fmt.Println(pkg.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(pkg.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(pkg.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(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetRoleId 缺少 roleid")
return 0
}
func GetDeptId(c *gin.Context) int {
data := ExtractClaims(c)
if data["deptid"] != nil {
i := int((data["deptid"]).(float64))
return i
}
fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetDeptId 缺少 deptid")
return 0
}
func GetDeptName(c *gin.Context) string {
data := ExtractClaims(c)
if data["deptkey"] != nil {
return (data["deptkey"]).(string)
}
fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetDeptName 缺少 deptkey")
return ""
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/qlanwl/goadmincore.git
git@gitee.com:qlanwl/goadmincore.git
qlanwl
goadmincore
goadmincore
c2af41c6b433

Search