fusenapi/utils/auth/user.go
laodaming 3d492ff720 fix
2023-06-07 11:35:04 +08:00

22 lines
414 B
Go

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}
}