first
This commit is contained in:
22
common/ctxdata/ctxData.go
Normal file
22
common/ctxdata/ctxData.go
Normal file
@@ -0,0 +1,22 @@
|
||||
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 {
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user