实现websocket基本功能

This commit is contained in:
GoEdgeLab
2020-09-26 19:54:02 +08:00
parent 5b1da8f5a2
commit 11f5c64fdb
22 changed files with 487 additions and 23 deletions

View File

@@ -36,6 +36,7 @@ type RPCClient struct {
httpCachePolicyClients []pb.HTTPCachePolicyServiceClient
httpFirewallPolicyClients []pb.HTTPFirewallPolicyServiceClient
httpLocationClients []pb.HTTPLocationServiceClient
httpWebsocketClients []pb.HTTPWebsocketServiceClient
}
func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
@@ -61,6 +62,7 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
httpCachePolicyClients := []pb.HTTPCachePolicyServiceClient{}
httpFirewallPolicyClients := []pb.HTTPFirewallPolicyServiceClient{}
httpLocationClients := []pb.HTTPLocationServiceClient{}
httpWebsocketClients := []pb.HTTPWebsocketServiceClient{}
conns := []*grpc.ClientConn{}
for _, endpoint := range apiConfig.RPC.Endpoints {
@@ -94,6 +96,7 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
httpCachePolicyClients = append(httpCachePolicyClients, pb.NewHTTPCachePolicyServiceClient(conn))
httpFirewallPolicyClients = append(httpFirewallPolicyClients, pb.NewHTTPFirewallPolicyServiceClient(conn))
httpLocationClients = append(httpLocationClients, pb.NewHTTPLocationServiceClient(conn))
httpWebsocketClients = append(httpWebsocketClients, pb.NewHTTPWebsocketServiceClient(conn))
}
return &RPCClient{
@@ -116,6 +119,7 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
httpCachePolicyClients: httpCachePolicyClients,
httpFirewallPolicyClients: httpFirewallPolicyClients,
httpLocationClients: httpLocationClients,
httpWebsocketClients: httpWebsocketClients,
}, nil
}
@@ -245,6 +249,13 @@ func (this *RPCClient) HTTPLocationRPC() pb.HTTPLocationServiceClient {
return nil
}
func (this *RPCClient) HTTPWebsocketRPC() pb.HTTPWebsocketServiceClient {
if len(this.httpWebsocketClients) > 0 {
return this.httpWebsocketClients[rands.Int(0, len(this.httpWebsocketClients)-1)]
}
return nil
}
func (this *RPCClient) Context(adminId int64) context.Context {
ctx := context.Background()
m := maps.Map{