From f4f52bfcc203b4670ea11574cfefaed8a49d5691 Mon Sep 17 00:00:00 2001 From: "vito.he" <hxmhlt@163.com> Date: Sat, 6 Apr 2019 00:21:55 +0800 Subject: [PATCH] if elseif else change to switch in zookeeper.registry --- registry/zookeeper/registry.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/registry/zookeeper/registry.go b/registry/zookeeper/registry.go index 5495724a5..fa01b0457 100644 --- a/registry/zookeeper/registry.go +++ b/registry/zookeeper/registry.go @@ -338,7 +338,9 @@ func (r *ZkRegistry) register(c registry.ServiceConfig) error { } params.Add("revision", revision) // revision鏄痯ox.xml涓璦pplication鐨剉ersion灞炴€х殑鍊� - if r.DubboType == registry.PROVIDER { + switch r.DubboType { + + case registry.PROVIDER: if conf, ok = c.(registry.ProviderServiceConfig); !ok { return jerrors.Errorf("conf is not ProviderServiceConfig") } @@ -392,7 +394,7 @@ func (r *ZkRegistry) register(c registry.ServiceConfig) error { dubboPath = fmt.Sprintf("/dubbo/%s/%s", conf.Service(), (registry.DubboType(registry.PROVIDER)).String()) log.Debug("provider path:%s, url:%s", dubboPath, rawURL) - } else if r.DubboType == registry.CONSUMER { + case registry.CONSUMER: dubboPath = fmt.Sprintf("/dubbo/%s/%s", c.Service(), registry.DubboNodes[registry.CONSUMER]) r.cltLock.Lock() err = r.client.Create(dubboPath) @@ -431,7 +433,7 @@ func (r *ZkRegistry) register(c registry.ServiceConfig) error { dubboPath = fmt.Sprintf("/dubbo/%s/%s", c.Service(), (registry.DubboType(registry.CONSUMER)).String()) log.Debug("consumer path:%s, url:%s", dubboPath, rawURL) - } else { + default: return jerrors.Errorf("@c{%v} type is not DefaultServiceConfig or DefaultProviderServiceConfig", c) } -- GitLab