fusenapi/utils/auth/user.go

22 lines
414 B
Go
Raw Normal View History

2023-06-07 03:35:04 +00:00
package auth
import (
"context"
"encoding/json"
"github.com/zeromicro/go-zero/core/logx"
)
type UserInfo struct {
UserId int64 `json:"userid"`
}
// 获取登录信息
func GetUserInfoFormCtx(ctx context.Context) UserInfo {
uid, err := ctx.Value("userid").(json.Number).Int64()
if err != nil {
logx.Error("parse uid form context err:", err.Error())
return UserInfo{}
}
return UserInfo{UserId: uid}
}