Skip to content

Commit

Permalink
Fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
flycash committed Jun 2, 2020
1 parent bdd9b71 commit 5f0084a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
3 changes: 3 additions & 0 deletions metadata/report/nacos/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions metadata/report/nacos/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 1 addition & 4 deletions registry/nacos/base_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 15 additions & 9 deletions remoting/nacos/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,32 @@ 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),
})
}
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
}

0 comments on commit 5f0084a

Please sign in to comment.