ClusterContext 集群上下文
(clusterId string, clusterSecret string)
| 128 | |
| 129 | // ClusterContext 集群上下文 |
| 130 | func (this *RPCClient) ClusterContext(clusterId string, clusterSecret string) context.Context { |
| 131 | ctx := context.Background() |
| 132 | m := maps.Map{ |
| 133 | "timestamp": time.Now().Unix(), |
| 134 | "type": "cluster", |
| 135 | "userId": 0, |
| 136 | } |
| 137 | method, err := encrypt.NewMethodInstance(teaconst.EncryptMethod, clusterSecret, clusterId) |
| 138 | if err != nil { |
| 139 | utils.PrintError(err) |
| 140 | return context.Background() |
| 141 | } |
| 142 | data, err := method.Encrypt(m.AsJSON()) |
| 143 | if err != nil { |
| 144 | utils.PrintError(err) |
| 145 | return context.Background() |
| 146 | } |
| 147 | token := base64.StdEncoding.EncodeToString(data) |
| 148 | ctx = metadata.AppendToOutgoingContext(ctx, "nodeId", clusterId, "token", token) |
| 149 | return ctx |
| 150 | } |
| 151 | |
| 152 | // Close 关闭连接 |
| 153 | func (this *RPCClient) Close() { |
no test coverage detected