1 Star 0 Fork 0

linxing / youye-core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
user.go 2.54 KB
一键复制 编辑 原始数据 按行查看 历史
Mark 提交于 2024-01-29 17:39 . rename package
package user
/*
import (
"fmt"
"github.com/gin-gonic/gin"
"gitee.com/linxing_3/youye-core/sdk/pkg"
jwt "gitee.com/linxing_3/youye-core/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 ""
}
*/
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/linxing_3/youye-core.git
git@gitee.com:linxing_3/youye-core.git
linxing_3
youye-core
youye-core
v0.0.1-202404291803

搜索帮助

344bd9b3 5694891 D2dac590 5694891