Context 节点上下文信息
()
| 104 | |
| 105 | // Context 节点上下文信息 |
| 106 | func (this *RPCClient) Context() context.Context { |
| 107 | var m = maps.Map{ |
| 108 | "timestamp": time.Now().Unix(), |
| 109 | "type": "node", |
| 110 | "userId": 0, |
| 111 | } |
| 112 | method, err := encrypt.NewMethodInstance(teaconst.EncryptMethod, this.apiConfig.Secret, this.apiConfig.NodeId) |
| 113 | if err != nil { |
| 114 | utils.PrintError(err) |
| 115 | return context.Background() |
| 116 | } |
| 117 | data, err := method.Encrypt(m.AsJSON()) |
| 118 | if err != nil { |
| 119 | utils.PrintError(err) |
| 120 | return context.Background() |
| 121 | } |
| 122 | var token = base64.StdEncoding.EncodeToString(data) |
| 123 | |
| 124 | var ctx = context.Background() |
| 125 | ctx = metadata.AppendToOutgoingContext(ctx, "nodeId", this.apiConfig.NodeId, "token", token) |
| 126 | return ctx |
| 127 | } |
| 128 | |
| 129 | // ClusterContext 集群上下文 |
| 130 | func (this *RPCClient) ClusterContext(clusterId string, clusterSecret string) context.Context { |