diff --git a/registry/service/service_discovery_registry.go b/registry/service/service_discovery_registry.go index c946b9890f60161b3ae1b7e8218759d69c1a3003..b3c9e6a632054e89e787aa45720b84d076a02971 100644 --- a/registry/service/service_discovery_registry.go +++ b/registry/service/service_discovery_registry.go @@ -276,7 +276,7 @@ func (s *serviceDiscoveryRegistry) findMappedServices(url common.URL) *gxset.Has } func (s *serviceDiscoveryRegistry) getExportedUrls(subscribedURL common.URL, serviceInstances []registry.ServiceInstance) []common.URL { - filterInstances := make([]registry.ServiceInstance, len(serviceInstances), len(serviceInstances)) + var filterInstances []registry.ServiceInstance for _, s := range serviceInstances { if !s.IsEnable() || !s.IsHealthy() { continue diff --git a/registry/service/synthesizer/rest/rest_subscribed_urls_synthesizer.go b/registry/service/synthesizer/rest/rest_subscribed_urls_synthesizer.go index 7d3de7a3cd0f044bb709d73dc986daaf584663bb..a7e7a5bc3065008197963f1f566f6a1593c15e58 100644 --- a/registry/service/synthesizer/rest/rest_subscribed_urls_synthesizer.go +++ b/registry/service/synthesizer/rest/rest_subscribed_urls_synthesizer.go @@ -22,6 +22,7 @@ import ( "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/registry" "github.com/apache/dubbo-go/registry/service/synthesizer" + "net/url" "strings" ) @@ -41,15 +42,16 @@ func (r RestSubscribedURLsSynthesizer) Support(subscribedURL *common.URL) bool { func (r RestSubscribedURLsSynthesizer) Synthesize(subscribedURL *common.URL, serviceInstances []registry.ServiceInstance) []common.URL { urls := make([]common.URL, len(serviceInstances), len(serviceInstances)) - for _, s := range serviceInstances { + for i, s := range serviceInstances { splitHost := strings.Split(s.GetHost(), ":") - url := common.NewURLWithOptions(common.WithProtocol(subscribedURL.Protocol), common.WithIp(splitHost[0]), + u := common.NewURLWithOptions(common.WithProtocol(subscribedURL.Protocol), common.WithIp(splitHost[0]), common.WithPort(splitHost[1]), common.WithPath(subscribedURL.GetParam(constant.INTERFACE_KEY, subscribedURL.Path)), + common.WithParams(url.Values{}), common.WithParamsValue(constant.SIDE_KEY, constant.PROVIDER_PROTOCOL), common.WithParamsValue(constant.APPLICATION_KEY, s.GetServiceName()), common.WithParamsValue(constant.REGISTRY_KEY, "true"), ) - urls = append(urls, *url) + urls[i] = *u } return urls } diff --git a/registry/service/synthesizer/rest/rest_subscribed_urls_synthesizer_test.go b/registry/service/synthesizer/rest/rest_subscribed_urls_synthesizer_test.go index 1e8c1172bdfefdf3b306302ae801e1a2170344ab..8ad1b5022785374d4c9b1aeee71b6a941a874106 100644 --- a/registry/service/synthesizer/rest/rest_subscribed_urls_synthesizer_test.go +++ b/registry/service/synthesizer/rest/rest_subscribed_urls_synthesizer_test.go @@ -22,6 +22,7 @@ import ( "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/registry" "github.com/stretchr/testify/assert" + "net/url" "testing" ) @@ -50,13 +51,19 @@ func TestRestSubscribedURLsSynthesizer_Synthesize(t *testing.T) { } var expectUrls []common.URL - u1, _ := common.NewURL("rest://127.0.0.1:80/org.apache.dubbo-go.mockService", common.WithParamsValue(constant.SIDE_KEY, - constant.PROVIDER_PROTOCOL), common.WithParamsValue(constant.APPLICATION_KEY, "test1"), + u1 := common.NewURLWithOptions(common.WithProtocol("rest"), common.WithIp("127.0.0.1"), + common.WithPort("80"), common.WithPath("org.apache.dubbo-go.mockService"), + common.WithParams(url.Values{}), + common.WithParamsValue(constant.SIDE_KEY, constant.PROVIDER_PROTOCOL), + common.WithParamsValue(constant.APPLICATION_KEY, "test1"), common.WithParamsValue(constant.REGISTRY_KEY, "true")) - u2, _ := common.NewURL("rest://127.0.0.2:8081/org.apache.dubbo-go.mockService", common.WithParamsValue(constant.SIDE_KEY, - constant.PROVIDER_PROTOCOL), common.WithParamsValue(constant.APPLICATION_KEY, "test2"), + u2 := common.NewURLWithOptions(common.WithProtocol("rest"), common.WithIp("127.0.0.2"), + common.WithPort("8081"), common.WithPath("org.apache.dubbo-go.mockService"), + common.WithParams(url.Values{}), + common.WithParamsValue(constant.SIDE_KEY, constant.PROVIDER_PROTOCOL), + common.WithParamsValue(constant.APPLICATION_KEY, "test2"), common.WithParamsValue(constant.REGISTRY_KEY, "true")) - expectUrls = append(expectUrls, u1, u2) + expectUrls = append(expectUrls, *u1, *u2) result := syn.Synthesize(&subUrl, instances) assert.Equal(t, expectUrls, result) }