mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-10 20:40:56 +08:00
对服务增加基础的数据统计/部分代码分Package
This commit is contained in:
13
internal/rpc/utils/mock.go
Normal file
13
internal/rpc/utils/mock.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package rpcutils
|
||||
|
||||
import "context"
|
||||
|
||||
type MockNodeContext struct {
|
||||
context.Context
|
||||
|
||||
NodeId int64
|
||||
}
|
||||
|
||||
func NewMockNodeContext(nodeId int64) context.Context {
|
||||
return &MockNodeContext{NodeId: nodeId}
|
||||
}
|
||||
@@ -56,6 +56,12 @@ func ValidateRequest(ctx context.Context, userTypes ...UserType) (userType UserT
|
||||
return
|
||||
}
|
||||
|
||||
// 是否是模拟测试
|
||||
mockCtx, isMock := ctx.(*MockNodeContext)
|
||||
if isMock {
|
||||
return UserTypeNode, mockCtx.NodeId, nil
|
||||
}
|
||||
|
||||
md, ok := metadata.FromIncomingContext(ctx)
|
||||
if !ok {
|
||||
return UserTypeNone, 0, errors.New("context: need 'nodeId'")
|
||||
|
||||
Reference in New Issue
Block a user