实现路径规则部分功能

This commit is contained in:
刘祥超
2020-09-21 19:51:50 +08:00
parent 47bf305df6
commit a4b806fa7e
50 changed files with 630 additions and 114 deletions

View File

@@ -35,6 +35,7 @@ type RPCClient struct {
httpAccessLogPolicyClients []pb.HTTPAccessLogPolicyServiceClient
httpCachePolicyClients []pb.HTTPCachePolicyServiceClient
httpFirewallPolicyClients []pb.HTTPFirewallPolicyServiceClient
httpLocationClients []pb.HTTPLocationServiceClient
}
func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
@@ -59,6 +60,7 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
httpAccessLogPolicyClients := []pb.HTTPAccessLogPolicyServiceClient{}
httpCachePolicyClients := []pb.HTTPCachePolicyServiceClient{}
httpFirewallPolicyClients := []pb.HTTPFirewallPolicyServiceClient{}
httpLocationClients := []pb.HTTPLocationServiceClient{}
conns := []*grpc.ClientConn{}
for _, endpoint := range apiConfig.RPC.Endpoints {
@@ -91,6 +93,7 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
httpAccessLogPolicyClients = append(httpAccessLogPolicyClients, pb.NewHTTPAccessLogPolicyServiceClient(conn))
httpCachePolicyClients = append(httpCachePolicyClients, pb.NewHTTPCachePolicyServiceClient(conn))
httpFirewallPolicyClients = append(httpFirewallPolicyClients, pb.NewHTTPFirewallPolicyServiceClient(conn))
httpLocationClients = append(httpLocationClients, pb.NewHTTPLocationServiceClient(conn))
}
return &RPCClient{
@@ -112,6 +115,7 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
httpAccessLogPolicyClients: httpAccessLogPolicyClients,
httpCachePolicyClients: httpCachePolicyClients,
httpFirewallPolicyClients: httpFirewallPolicyClients,
httpLocationClients: httpLocationClients,
}, nil
}
@@ -234,6 +238,13 @@ func (this *RPCClient) HTTPFirewallPolicyRPC() pb.HTTPFirewallPolicyServiceClien
return nil
}
func (this *RPCClient) HTTPLocationRPC() pb.HTTPLocationServiceClient {
if len(this.httpLocationClients) > 0 {
return this.httpLocationClients[rands.Int(0, len(this.httpLocationClients)-1)]
}
return nil
}
func (this *RPCClient) Context(adminId int64) context.Context {
ctx := context.Background()
m := maps.Map{