diff --git a/metadata/report/nacos/report.go b/metadata/report/nacos/report.go index 9dbec518220c3692257d29b1f01d78b0894f249e..63ca7ec24024f4ca63949895dece7d2cab6387eb 100644 --- a/metadata/report/nacos/report.go +++ b/metadata/report/nacos/report.go @@ -51,6 +51,7 @@ type nacosMetadataReport struct { } // StoreProviderMetadata will store the metadata +// metadata including the basic info of the server, provider info, and other user custom info func (n *nacosMetadataReport) StoreProviderMetadata(providerIdentifier *identifier.MetadataIdentifier, serviceDefinitions string) error { return n.storeMetadata(vo.ConfigParam{ DataId: providerIdentifier.GetIdentifierKey(), @@ -60,6 +61,7 @@ func (n *nacosMetadataReport) StoreProviderMetadata(providerIdentifier *identifi } // StoreConsumerMetadata will store the metadata +// metadata including the basic info of the server, consumer info, and other user custom info func (n *nacosMetadataReport) StoreConsumerMetadata(consumerMetadataIdentifier *identifier.MetadataIdentifier, serviceParameterString string) error { return n.storeMetadata(vo.ConfigParam{ DataId: consumerMetadataIdentifier.GetIdentifierKey(), @@ -69,6 +71,7 @@ func (n *nacosMetadataReport) StoreConsumerMetadata(consumerMetadataIdentifier * } // SaveServiceMetadata will store the metadata +// metadata including the basic info of the server, service info, and other user custom info func (n *nacosMetadataReport) SaveServiceMetadata(metadataIdentifier *identifier.ServiceMetadataIdentifier, url common.URL) error { return n.storeMetadata(vo.ConfigParam{ DataId: metadataIdentifier.GetIdentifierKey(), diff --git a/metadata/report/nacos/report_test.go b/metadata/report/nacos/report_test.go index 711e6281a295005501ad9384f6fc3433c2e2830d..19ca2e5a480766e2c0ae8d8dbd7d9b294ce4b905 100644 --- a/metadata/report/nacos/report_test.go +++ b/metadata/report/nacos/report_test.go @@ -20,9 +20,13 @@ package nacos import ( "strconv" "testing" +) +import ( "github.com/stretchr/testify/assert" +) +import ( "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/extension" diff --git a/registry/nacos/base_registry.go b/registry/nacos/base_registry.go index 636ffc302ee30a58ea1b9160d498c3e4968556cb..cb1c32dce5c3618f30e2b91af337086097b15a41 100644 --- a/registry/nacos/base_registry.go +++ b/registry/nacos/base_registry.go @@ -17,16 +17,13 @@ package nacos -import ( - "github.com/apache/dubbo-go/remoting/nacos" -) - import ( "github.com/nacos-group/nacos-sdk-go/clients/naming_client" ) import ( "github.com/apache/dubbo-go/common" + "github.com/apache/dubbo-go/remoting/nacos" ) // baseRegistry is the parent of both interface-level registry diff --git a/remoting/nacos/builder.go b/remoting/nacos/builder.go index bf89d4a7b97399054b500a9c6ec52d664d5d8799..4da309936a283a78617ed8fa98fdad8933f5e70e 100644 --- a/remoting/nacos/builder.go +++ b/remoting/nacos/builder.go @@ -70,7 +70,10 @@ func getNacosConfig(url *common.URL) (map[string]interface{}, error) { if err != nil { return nil, perrors.WithMessagef(err, "split [%s] ", addr) } - port, _ := strconv.Atoi(portStr) + port, err := strconv.Atoi(portStr) + if err != nil { + return configMap, perrors.WithMessage(err, "the port string is invalid. "+portStr) + } serverConfigs = append(serverConfigs, nacosConstant.ServerConfig{ IpAddr: ip, Port: uint64(port), @@ -78,18 +81,21 @@ func getNacosConfig(url *common.URL) (map[string]interface{}, error) { } configMap["serverConfigs"] = serverConfigs - var clientConfig nacosConstant.ClientConfig timeout, err := time.ParseDuration(url.GetParam(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT)) if err != nil { return nil, err } - clientConfig.TimeoutMs = uint64(timeout.Seconds() * 1000) - clientConfig.ListenInterval = 2 * clientConfig.TimeoutMs - clientConfig.CacheDir = url.GetParam(constant.NACOS_CACHE_DIR_KEY, "") - clientConfig.LogDir = url.GetParam(constant.NACOS_LOG_DIR_KEY, "") - clientConfig.Endpoint = url.GetParam(constant.NACOS_ENDPOINT, "") - clientConfig.NotLoadCacheAtStart = true - configMap["clientConfig"] = clientConfig + + timeoutMs := uint64(timeout.Nanoseconds() / constant.MsToNanoRate) + + configMap["clientConfig"] = nacosConstant.ClientConfig{ + TimeoutMs: timeoutMs, + ListenInterval: 2 * timeoutMs, + CacheDir: url.GetParam(constant.NACOS_CACHE_DIR_KEY, ""), + LogDir: url.GetParam(constant.NACOS_LOG_DIR_KEY, ""), + Endpoint: url.GetParam(constant.NACOS_ENDPOINT, ""), + NotLoadCacheAtStart: true, + } return configMap, nil }