Skip to content
Snippets Groups Projects
Commit 3ee8c7c5 authored by flycash's avatar flycash
Browse files

Fix review and test

parent 3b24cb01
No related branches found
No related tags found
No related merge requests found
...@@ -140,7 +140,7 @@ func newNacosClient(name string, nacosAddrs []string, timeout time.Duration) (*N ...@@ -140,7 +140,7 @@ func newNacosClient(name string, nacosAddrs []string, timeout time.Duration) (*N
}, },
} }
svrConfList := []nacosconst.ServerConfig{} svrConfList := make([]nacosconst.ServerConfig, 0, len(n.NacosAddrs))
for _, nacosAddr := range n.NacosAddrs { for _, nacosAddr := range n.NacosAddrs {
split := strings.Split(nacosAddr, ":") split := strings.Split(nacosAddr, ":")
port, err := strconv.ParseUint(split[1], 10, 64) port, err := strconv.ParseUint(split[1], 10, 64)
......
...@@ -49,7 +49,7 @@ type nacosClientFacade interface { ...@@ -49,7 +49,7 @@ type nacosClientFacade interface {
// HandleClientRestart Restart client handler // HandleClientRestart Restart client handler
func HandleClientRestart(r nacosClientFacade) { func HandleClientRestart(r nacosClientFacade) {
var ( var (
err error err error
failTimes int failTimes int
) )
......
...@@ -162,7 +162,7 @@ func (r *BaseRegistry) service(c common.URL) string { ...@@ -162,7 +162,7 @@ func (r *BaseRegistry) service(c common.URL) string {
func (r *BaseRegistry) RestartCallBack() bool { func (r *BaseRegistry) RestartCallBack() bool {
// copy r.services // copy r.services
services := []common.URL{} services := make([]common.URL, 0, len(r.services))
for _, confIf := range r.services { for _, confIf := range r.services {
services = append(services, confIf) services = append(services, confIf)
} }
...@@ -236,9 +236,11 @@ func (r *BaseRegistry) providerRegistry(c common.URL, params url.Values) (string ...@@ -236,9 +236,11 @@ func (r *BaseRegistry) providerRegistry(c common.URL, params url.Values) (string
return "", "", perrors.Errorf("conf{Path:%s, Methods:%s}", c.Path, c.Methods) return "", "", perrors.Errorf("conf{Path:%s, Methods:%s}", c.Path, c.Methods)
} }
dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), common.DubboNodes[common.PROVIDER]) dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), common.DubboNodes[common.PROVIDER])
r.cltLock.Lock() func() {
err = r.facadeBasedRegistry.CreatePath(dubboPath) r.cltLock.Lock()
r.cltLock.Unlock() defer r.cltLock.Unlock()
err = r.facadeBasedRegistry.CreatePath(dubboPath)
}()
if err != nil { if err != nil {
logger.Errorf("facadeBasedRegistry.CreatePath(path{%s}) = error{%#v}", dubboPath, perrors.WithStack(err)) logger.Errorf("facadeBasedRegistry.CreatePath(path{%s}) = error{%#v}", dubboPath, perrors.WithStack(err))
return "", "", perrors.WithMessagef(err, "facadeBasedRegistry.CreatePath(path:%s)", dubboPath) return "", "", perrors.WithMessagef(err, "facadeBasedRegistry.CreatePath(path:%s)", dubboPath)
...@@ -260,10 +262,11 @@ func (r *BaseRegistry) providerRegistry(c common.URL, params url.Values) (string ...@@ -260,10 +262,11 @@ func (r *BaseRegistry) providerRegistry(c common.URL, params url.Values) (string
logger.Debugf("provider url params:%#v", params) logger.Debugf("provider url params:%#v", params)
var host string var host string
if c.Ip == "" { if c.Ip == "" {
host = localIP + ":" + c.Port host = localIP
} else { } else {
host = c.Ip + ":" + c.Port host = c.Ip
} }
host += ":" + c.Port
rawURL = fmt.Sprintf("%s://%s%s?%s", c.Protocol, host, c.Path, params.Encode()) rawURL = fmt.Sprintf("%s://%s%s?%s", c.Protocol, host, c.Path, params.Encode())
// Print your own registration service providers. // Print your own registration service providers.
...@@ -280,17 +283,24 @@ func (r *BaseRegistry) consumerRegistry(c common.URL, params url.Values) (string ...@@ -280,17 +283,24 @@ func (r *BaseRegistry) consumerRegistry(c common.URL, params url.Values) (string
err error err error
) )
dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), common.DubboNodes[common.CONSUMER]) dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), common.DubboNodes[common.CONSUMER])
r.cltLock.Lock()
err = r.facadeBasedRegistry.CreatePath(dubboPath) func() {
r.cltLock.Unlock() r.cltLock.Lock()
err = r.facadeBasedRegistry.CreatePath(dubboPath)
r.cltLock.Unlock()
}()
if err != nil { if err != nil {
logger.Errorf("facadeBasedRegistry.CreatePath(path{%s}) = error{%v}", dubboPath, perrors.WithStack(err)) logger.Errorf("facadeBasedRegistry.CreatePath(path{%s}) = error{%v}", dubboPath, perrors.WithStack(err))
return "", "", perrors.WithStack(err) return "", "", perrors.WithStack(err)
} }
dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), common.DubboNodes[common.PROVIDER]) dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), common.DubboNodes[common.PROVIDER])
r.cltLock.Lock()
err = r.facadeBasedRegistry.CreatePath(dubboPath) func() {
r.cltLock.Unlock() r.cltLock.Lock()
defer r.cltLock.Unlock()
err = r.facadeBasedRegistry.CreatePath(dubboPath)
}()
if err != nil { if err != nil {
logger.Errorf("facadeBasedRegistry.CreatePath(path{%s}) = error{%v}", dubboPath, perrors.WithStack(err)) logger.Errorf("facadeBasedRegistry.CreatePath(path{%s}) = error{%v}", dubboPath, perrors.WithStack(err))
return "", "", perrors.WithStack(err) return "", "", perrors.WithStack(err)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment