Ai
1 Star 0 Fork 0

xingang/gcore2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
RequestHelper.go 780 Bytes
一键复制 编辑 原始数据 按行查看 历史
xingang 提交于 2023-02-14 15:00 +08:00 . init
package middlewares
import (
"github.com/gin-gonic/gin"
)
type RequestHelper struct {
}
type UserSessionLoginInfo struct {
TenantID int `json:"tenantId"`
Token string `json:"token"`
//LoginType string `json:"loginType"`
UserID int `json:"userId"`
LoginName string `json:"loginName"`
UserName string `json:"userName"`
}
func GetUserToken(c *gin.Context) *UserSessionLoginInfo {
var token = c.Request.Header.Get("token")
if token == "" {
var cook, _ = c.Request.Cookie("token")
if cook != nil {
token = cook.Value
}
}
if token == "" {
return nil
}
var info = NewUserTokenCache().GetTokenInfo(token)
return info
}
func GetUserIdByToken(c *gin.Context) int {
token := GetUserToken(c)
if token == nil {
return 0
}
return token.UserID
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/qq358678184_admin/gcore2.git
git@gitee.com:qq358678184_admin/gcore2.git
qq358678184_admin
gcore2
gcore2
a1f72da8efa7

搜索帮助