mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-09 20:10:27 +08:00
优化代码
This commit is contained in:
@@ -27,9 +27,6 @@ type RPCClient struct {
|
|||||||
apiConfig *configs.APIConfig
|
apiConfig *configs.APIConfig
|
||||||
conns []*grpc.ClientConn
|
conns []*grpc.ClientConn
|
||||||
|
|
||||||
ctx context.Context
|
|
||||||
ctxUpdatedAt int64
|
|
||||||
|
|
||||||
locker sync.RWMutex
|
locker sync.RWMutex
|
||||||
|
|
||||||
NodeRPC pb.NodeServiceClient
|
NodeRPC pb.NodeServiceClient
|
||||||
@@ -97,12 +94,6 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
|
|||||||
|
|
||||||
// Context 节点上下文信息
|
// Context 节点上下文信息
|
||||||
func (this *RPCClient) Context() context.Context {
|
func (this *RPCClient) Context() context.Context {
|
||||||
var currentTime = time.Now().Unix()
|
|
||||||
|
|
||||||
if this.ctx != nil && this.ctxUpdatedAt > currentTime-5 {
|
|
||||||
return this.ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
var m = maps.Map{
|
var m = maps.Map{
|
||||||
"timestamp": time.Now().Unix(),
|
"timestamp": time.Now().Unix(),
|
||||||
"type": "node",
|
"type": "node",
|
||||||
@@ -122,10 +113,6 @@ func (this *RPCClient) Context() context.Context {
|
|||||||
|
|
||||||
var ctx = context.Background()
|
var ctx = context.Background()
|
||||||
ctx = metadata.AppendToOutgoingContext(ctx, "nodeId", this.apiConfig.NodeId, "token", token)
|
ctx = metadata.AppendToOutgoingContext(ctx, "nodeId", this.apiConfig.NodeId, "token", token)
|
||||||
|
|
||||||
this.ctxUpdatedAt = currentTime
|
|
||||||
this.ctx = ctx
|
|
||||||
|
|
||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user