add Refresh
This commit is contained in:
@@ -16,17 +16,19 @@ type UserInfo struct {
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// GetUserFromCtx 从rpc metadata获取用户
|
||||
func GetUserFromCtx(ctx context.Context) UserInfo {
|
||||
md, ok := metadata.FromIncomingContext(ctx)
|
||||
if !ok {
|
||||
return UserInfo{Valid: false}
|
||||
}
|
||||
|
||||
uidList := md.Get("x-user-id")
|
||||
nameList := md.Get("x-user-name")
|
||||
refreshList := md.Get("x-refresh")
|
||||
|
||||
if len(refreshList) == 0 {
|
||||
refreshList = md.Get("X-Refresh")
|
||||
}
|
||||
|
||||
rawUID := ""
|
||||
encodeName := ""
|
||||
refresh := ""
|
||||
@@ -41,7 +43,7 @@ func GetUserFromCtx(ctx context.Context) UserInfo {
|
||||
}
|
||||
|
||||
if rawUID == "" {
|
||||
return UserInfo{Valid: false}
|
||||
return UserInfo{Valid: false, Refresh: refresh}
|
||||
}
|
||||
|
||||
uid, err := strconv.ParseInt(rawUID, 10, 64)
|
||||
@@ -54,7 +56,6 @@ func GetUserFromCtx(ctx context.Context) UserInfo {
|
||||
}
|
||||
}
|
||||
|
||||
// 解码中文
|
||||
userName, _ := url.QueryUnescape(encodeName)
|
||||
|
||||
return UserInfo{
|
||||
|
||||
Reference in New Issue
Block a user