22 lines
414 B
Go
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}
|
|
}
|