This commit is contained in:
2024-11-03 15:28:10 +08:00
commit cca66faed5
113 changed files with 4349 additions and 0 deletions

22
common/ctxdata/ctxData.go Normal file
View 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
}