GetUidFromCtx CommonJwtAuthMiddleware
This commit is contained in:
parent
a8c1fbbc1a
commit
90b00d9e16
|
@ -3,12 +3,20 @@ package ctxdata
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
// CtxKeyJwtUserId get uid from ctx
|
||||
var CtxKeyJwtUserId = "jwtUserId"
|
||||
|
||||
func GetUidFromCtx(ctx context.Context) int64 {
|
||||
uid ,_ := ctx.Value(CtxKeyJwtUserId).(json.Number).Int64()
|
||||
var uid int64
|
||||
if jsonUid, ok := ctx.Value(CtxKeyJwtUserId).(json.Number); ok {
|
||||
if int64Uid, err := jsonUid.Int64(); err == nil {
|
||||
uid = int64Uid
|
||||
} else {
|
||||
logx.WithContext(ctx).Errorf("GetUidFromCtx err : %+v", err)
|
||||
}
|
||||
}
|
||||
return uid
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue