chore: init bj_power monorepo (dashboard/mes/wms/wms_client/workstation), clear subproject git metadata and align naming to folder names
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package xhttp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
// CtxKeyJwtUserId get uid from ctx
|
||||
var CtxKeyJwtUserId = "jwtUserId"
|
||||
|
||||
// CtxKeyJwtOpenId get openid from ctx
|
||||
var CtxKeyJwtOpenId = "jwtOpenId"
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func GetOidFromCtx(ctx context.Context) string {
|
||||
if jsonUid, ok := ctx.Value(CtxKeyJwtOpenId).(string); ok {
|
||||
return jsonUid
|
||||
}
|
||||
logx.WithContext(ctx).Error("GetOidFromCtx failed")
|
||||
return ""
|
||||
}
|
||||
Reference in New Issue
Block a user