wenxuwan commented on a change in pull request #1479:
URL: https://github.com/apache/dubbo-go/pull/1479#discussion_r713921815



##########
File path: config_center/nacos/client.go
##########
@@ -18,173 +18,63 @@
 package nacos
 
 import (
-       "strconv"
-       "strings"
        "sync"
        "time"
 )
 
 import (
-       "github.com/nacos-group/nacos-sdk-go/clients"
-       "github.com/nacos-group/nacos-sdk-go/clients/config_client"
-       nacosconst "github.com/nacos-group/nacos-sdk-go/common/constant"
+       nacosClient "github.com/dubbogo/gost/database/kv/nacos"
        perrors "github.com/pkg/errors"
 )
 
 import (
-       "github.com/apache/dubbo-go/common"
-       "github.com/apache/dubbo-go/common/constant"
        "github.com/apache/dubbo-go/common/logger"
+       "github.com/apache/dubbo-go/remoting/nacos"
 )
 
-// NacosClient Nacos client
+// NacosClient Nacos configClient
 type NacosClient struct {
-       name       string
-       NacosAddrs []string
-       sync.Mutex // for Client
-       client     *config_client.IConfigClient
-       exit       chan struct{}
-       Timeout    time.Duration
-       once       sync.Once
-       onceClose  func()
+       name         string
+       NacosAddrs   []string
+       sync.Mutex   // for Client
+       configClient *nacosClient.NacosConfigClient
+       exit         chan struct{}
+       Timeout      time.Duration
+       once         sync.Once
+       onceClose    func()
 }
 
 // Client Get Client
-func (n *NacosClient) Client() *config_client.IConfigClient {
-       return n.client
+func (n *NacosClient) Client() *nacosClient.NacosConfigClient {
+       return n.configClient
 }
 
-// SetClient Set client
-func (n *NacosClient) SetClient(client *config_client.IConfigClient) {
+// SetClient Set configClient
+func (n *NacosClient) SetClient(configClient *nacosClient.NacosConfigClient) {
        n.Lock()
-       n.client = client
+       n.configClient = configClient
        n.Unlock()
 }
 
-type option func(*options)
-
-type options struct {
-       nacosName string
-       //client    *NacosClient
-}
-
-// WithNacosName Set nacos name
-func WithNacosName(name string) option {
-       return func(opt *options) {
-               opt.nacosName = name
-       }
-}
-
-// ValidateNacosClient Validate nacos client , if null then create it
-func ValidateNacosClient(container nacosClientFacade, opts ...option) error {
+// ValidateNacosClient Validate nacos configClient , if null then create it
+func ValidateNacosClient(container nacosClientFacade) error {
        if container == nil {
                return perrors.Errorf("container can not be null")
        }
-       os := &options{}
-       for _, opt := range opts {
-               opt(os)
-       }
-
        url := container.GetURL()
-       timeout, err := 
time.ParseDuration(url.GetParam(constant.CONFIG_TIMEOUT_KEY, 
constant.DEFAULT_REG_TIMEOUT))
-       if err != nil {
-               logger.Errorf("invalid timeout config %+v,got err %+v",
-                       url.GetParam(constant.CONFIG_TIMEOUT_KEY, 
constant.DEFAULT_REG_TIMEOUT), err)
-               return perrors.WithMessagef(err, "newNacosClient(address:%+v)", 
url.Location)
-       }
-       nacosAddresses := strings.Split(url.Location, ",")
-       if container.NacosClient() == nil {
-               //in dubbo ,every registry only connect one node ,so this is 
[]string{r.Address}
-               newClient, err := newNacosClient(os.nacosName, nacosAddresses, 
timeout, url)
+       if container.NacosClient() == nil || container.NacosClient().Client() 
== nil {
+               // in dubbo ,every registry only connect one node ,so this is 
[]string{r.Address}
+               newClient, err := nacos.NewNacosConfigClientByUrl(url)
                if err != nil {
-                       logger.Errorf("newNacosClient(name{%s}, nacos 
address{%v}, timeout{%d}) = error{%v}",
-                               os.nacosName, url.Location, timeout.String(), 
err)
+                       logger.Errorf("ValidateNacosClient(name{%s}, nacos 
address{%v} = error{%v}", url.Location, err)
                        return perrors.WithMessagef(err, 
"newNacosClient(address:%+v)", url.Location)
                }
                container.SetNacosClient(newClient)
        }
-
-       if container.NacosClient().Client() == nil {
-               configClient, err := initNacosConfigClient(nacosAddresses, 
timeout, url)
-               if err != nil {
-                       
logger.Errorf("initNacosConfigClient(addr:%+v,timeout:%v,url:%v) = err %+v",
-                               nacosAddresses, timeout.String(), url, err)
-                       return perrors.WithMessagef(err, 
"newNacosClient(address:%+v)", url.Location)
-               }
-               container.NacosClient().SetClient(&configClient)
-
-       }
-
        return perrors.WithMessagef(nil, "newNacosClient(address:%+v)", 
url.PrimitiveURL)

Review comment:
       here return nil is better




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to