diff --git a/cluster/cluster_impl/failover_cluster.go b/cluster/cluster_impl/failover_cluster.go index f85680465243d4d42d62452de64d56e86e65aa2d..1f427019de35e04df76d494fb7587e4ad3b8ece0 100644 --- a/cluster/cluster_impl/failover_cluster.go +++ b/cluster/cluster_impl/failover_cluster.go @@ -12,10 +12,10 @@ type failoverCluster struct { const name = "failover" func init() { - extension.SetCluster(name, NewFailoverCluster) + extension.SetCluster(name, newFailoverCluster) } -func NewFailoverCluster() cluster.Cluster { +func newFailoverCluster() cluster.Cluster { return &failoverCluster{} } diff --git a/cluster/cluster_impl/registry_aware_cluster.go b/cluster/cluster_impl/registry_aware_cluster.go index f722c3e9bd0c29d54b6296a9eeb9b981c25ac128..ec89b3bfbfa5fa68906ff08a9ba823a8dd493b3c 100644 --- a/cluster/cluster_impl/registry_aware_cluster.go +++ b/cluster/cluster_impl/registry_aware_cluster.go @@ -10,10 +10,10 @@ type registryAwareCluster struct { } func init() { - extension.SetCluster("registryAware", NewRegistryAwareCluster) + extension.SetCluster("registryAware", newRegistryAwareCluster) } -func NewRegistryAwareCluster() cluster.Cluster { +func newRegistryAwareCluster() cluster.Cluster { return ®istryAwareCluster{} } diff --git a/cluster/loadbalance/random.go b/cluster/loadbalance/random.go index 2772f17e3765f78bb6d637d4fa27e5655bffdebd..a86b36e4356b0a10232ea6403b881155a329545e 100644 --- a/cluster/loadbalance/random.go +++ b/cluster/loadbalance/random.go @@ -14,13 +14,13 @@ import ( const name = "random" func init() { - extension.SetLoadbalance(name, NewRandomLoadBalance) + extension.SetLoadbalance(name, newRandomLoadBalance) } type randomLoadBalance struct { } -func NewRandomLoadBalance() cluster.LoadBalance { +func newRandomLoadBalance() cluster.LoadBalance { return &randomLoadBalance{} } diff --git a/registry/protocol/protocol.go b/registry/protocol/protocol.go index 80931727035bf199595d114bdd48821466a48233..9d955f0c7fc27b743b8f8ab539c9698af29aecce 100644 --- a/registry/protocol/protocol.go +++ b/registry/protocol/protocol.go @@ -18,9 +18,9 @@ import ( directory2 "github.com/dubbo/go-for-apache-dubbo/registry/directory" ) -var registryProtocol *RegistryProtocol +var regProtocol *registryProtocol -type RegistryProtocol struct { +type registryProtocol struct { invokers []protocol.Invoker // Registry Map<RegistryAddress, Registry> registries sync.Map @@ -33,8 +33,8 @@ func init() { extension.SetProtocol("registry", GetProtocol) } -func NewRegistryProtocol() *RegistryProtocol { - return &RegistryProtocol{ +func newRegistryProtocol() *registryProtocol { + return ®istryProtocol{ registries: sync.Map{}, bounds: sync.Map{}, } @@ -47,7 +47,7 @@ func getRegistry(regUrl *common.URL) registry.Registry { } return reg } -func (proto *RegistryProtocol) Refer(url common.URL) protocol.Invoker { +func (proto *registryProtocol) Refer(url common.URL) protocol.Invoker { var registryUrl = url var serviceUrl = registryUrl.SubURL @@ -84,7 +84,7 @@ func (proto *RegistryProtocol) Refer(url common.URL) protocol.Invoker { return invoker } -func (proto *RegistryProtocol) Export(invoker protocol.Invoker) protocol.Exporter { +func (proto *registryProtocol) Export(invoker protocol.Invoker) protocol.Exporter { registryUrl := proto.getRegistryUrl(invoker) providerUrl := proto.getProviderUrl(invoker) @@ -119,7 +119,7 @@ func (proto *RegistryProtocol) Export(invoker protocol.Invoker) protocol.Exporte } -func (proto *RegistryProtocol) Destroy() { +func (proto *registryProtocol) Destroy() { for _, ivk := range proto.invokers { ivk.Destroy() } @@ -142,7 +142,7 @@ func (proto *RegistryProtocol) Destroy() { }) } -func (*RegistryProtocol) getRegistryUrl(invoker protocol.Invoker) common.URL { +func (*registryProtocol) getRegistryUrl(invoker protocol.Invoker) common.URL { //here add * for return a new url url := invoker.GetUrl() //if the protocol == registry ,set protocol the registry value in url.params @@ -153,16 +153,16 @@ func (*RegistryProtocol) getRegistryUrl(invoker protocol.Invoker) common.URL { return url } -func (*RegistryProtocol) getProviderUrl(invoker protocol.Invoker) common.URL { +func (*registryProtocol) getProviderUrl(invoker protocol.Invoker) common.URL { url := invoker.GetUrl() return *url.SubURL } func GetProtocol() protocol.Protocol { - if registryProtocol != nil { - return registryProtocol + if regProtocol != nil { + return regProtocol } - return NewRegistryProtocol() + return newRegistryProtocol() } type wrappedInvoker struct { diff --git a/registry/protocol/protocol_test.go b/registry/protocol/protocol_test.go index 93b5c22bca7596609c5cd3b440684b4fff51815c..15b8e772a22d58a8fae1d02632d3a7771456ddcd 100644 --- a/registry/protocol/protocol_test.go +++ b/registry/protocol/protocol_test.go @@ -17,7 +17,7 @@ import ( "github.com/dubbo/go-for-apache-dubbo/registry" ) -func referNormal(t *testing.T, regProtocol *RegistryProtocol) { +func referNormal(t *testing.T, regProtocol *registryProtocol) { extension.SetProtocol("registry", GetProtocol) extension.SetRegistry("mock", registry.NewMockRegistry) extension.SetProtocol(protocolwrapper.FILTER, protocolwrapper.NewMockProtocolFilter) @@ -33,12 +33,12 @@ func referNormal(t *testing.T, regProtocol *RegistryProtocol) { assert.Equal(t, invoker.GetUrl().String(), url.String()) } func TestRefer(t *testing.T) { - regProtocol := NewRegistryProtocol() + regProtocol := newRegistryProtocol() referNormal(t, regProtocol) } func TestMultiRegRefer(t *testing.T) { - regProtocol := NewRegistryProtocol() + regProtocol := newRegistryProtocol() referNormal(t, regProtocol) url2, _ := common.NewURL(context.TODO(), "mock://127.0.0.1:2222") suburl2, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000//", common.WithParamsValue(constant.CLUSTER_KEY, "mock")) @@ -55,7 +55,7 @@ func TestMultiRegRefer(t *testing.T) { } func TestOneRegRefer(t *testing.T) { - regProtocol := NewRegistryProtocol() + regProtocol := newRegistryProtocol() referNormal(t, regProtocol) url2, _ := common.NewURL(context.TODO(), "mock://127.0.0.1:1111") @@ -71,7 +71,7 @@ func TestOneRegRefer(t *testing.T) { }) assert.Equal(t, count, 1) } -func exporterNormal(t *testing.T, regProtocol *RegistryProtocol) { +func exporterNormal(t *testing.T, regProtocol *registryProtocol) { extension.SetProtocol("registry", GetProtocol) extension.SetRegistry("mock", registry.NewMockRegistry) extension.SetProtocol(protocolwrapper.FILTER, protocolwrapper.NewMockProtocolFilter) @@ -87,12 +87,12 @@ func exporterNormal(t *testing.T, regProtocol *RegistryProtocol) { } func TestExporter(t *testing.T) { - regProtocol := NewRegistryProtocol() + regProtocol := newRegistryProtocol() exporterNormal(t, regProtocol) } func TestMultiRegAndMultiProtoExporter(t *testing.T) { - regProtocol := NewRegistryProtocol() + regProtocol := newRegistryProtocol() exporterNormal(t, regProtocol) url2, _ := common.NewURL(context.TODO(), "mock://127.0.0.1:2222") @@ -118,7 +118,7 @@ func TestMultiRegAndMultiProtoExporter(t *testing.T) { } func TestOneRegAndProtoExporter(t *testing.T) { - regProtocol := NewRegistryProtocol() + regProtocol := newRegistryProtocol() exporterNormal(t, regProtocol) url2, _ := common.NewURL(context.TODO(), "mock://127.0.0.1:1111") @@ -144,7 +144,7 @@ func TestOneRegAndProtoExporter(t *testing.T) { } func TestDestry(t *testing.T) { - regProtocol := NewRegistryProtocol() + regProtocol := newRegistryProtocol() referNormal(t, regProtocol) exporterNormal(t, regProtocol) diff --git a/registry/zookeeper/listener.go b/registry/zookeeper/listener.go index 1895224050f496305ecc5bfae8e2a072d8979069..8a27d09901092f3de74fb896c6b1888851258100 100644 --- a/registry/zookeeper/listener.go +++ b/registry/zookeeper/listener.go @@ -38,10 +38,10 @@ type zkEventListener struct { serviceMapLock sync.Mutex serviceMap map[string]struct{} wg sync.WaitGroup - registry *ZkRegistry + registry *zkRegistry } -func newZkEventListener(registry *ZkRegistry, client *zookeeperClient) *zkEventListener { +func newZkEventListener(registry *zkRegistry, client *zookeeperClient) *zkEventListener { return &zkEventListener{ client: client, registry: registry, diff --git a/registry/zookeeper/registry.go b/registry/zookeeper/registry.go index 5660261f647ca0ce7575dbdff42d07c458d4d82e..15276daa37e5c6c42347e353ab455a85bc0fc77d 100644 --- a/registry/zookeeper/registry.go +++ b/registry/zookeeper/registry.go @@ -40,15 +40,15 @@ var ( func init() { processID = fmt.Sprintf("%d", os.Getpid()) localIP, _ = gxnet.GetLocalIP() - //plugins.PluggableRegistries["zookeeper"] = NewZkRegistry - extension.SetRegistry("zookeeper", NewZkRegistry) + //plugins.PluggableRegistries["zookeeper"] = newZkRegistry + extension.SetRegistry("zookeeper", newZkRegistry) } ///////////////////////////////////// // zookeeper registry ///////////////////////////////////// -type ZkRegistry struct { +type zkRegistry struct { context context.Context *common.URL birth int64 // time of file birth, seconds since Epoch; 0 if unknown @@ -66,13 +66,13 @@ type ZkRegistry struct { zkPath map[string]int // key = protocol://ip:port/interface } -func NewZkRegistry(url *common.URL) (registry.Registry, error) { +func newZkRegistry(url *common.URL) (registry.Registry, error) { var ( err error - r *ZkRegistry + r *zkRegistry ) - r = &ZkRegistry{ + r = &zkRegistry{ URL: url, birth: time.Now().UnixNano(), done: make(chan struct{}), @@ -103,15 +103,15 @@ func NewZkRegistry(url *common.URL) (registry.Registry, error) { return r, nil } -func NewMockZkRegistry(url *common.URL) (*zk.TestCluster, *ZkRegistry, error) { +func newMockZkRegistry(url *common.URL) (*zk.TestCluster, *zkRegistry, error) { var ( err error - r *ZkRegistry + r *zkRegistry c *zk.TestCluster //event <-chan zk.Event ) - r = &ZkRegistry{ + r = &zkRegistry{ URL: url, birth: time.Now().UnixNano(), done: make(chan struct{}), @@ -134,11 +134,11 @@ func NewMockZkRegistry(url *common.URL) (*zk.TestCluster, *ZkRegistry, error) { return c, r, nil } -func (r *ZkRegistry) GetUrl() common.URL { +func (r *zkRegistry) GetUrl() common.URL { return *r.URL } -func (r *ZkRegistry) Destroy() { +func (r *zkRegistry) Destroy() { if r.listener != nil { r.listener.Close() } @@ -147,7 +147,7 @@ func (r *ZkRegistry) Destroy() { r.closeRegisters() } -func (r *ZkRegistry) validateZookeeperClient() error { +func (r *zkRegistry) validateZookeeperClient() error { var ( err error ) @@ -182,7 +182,7 @@ func (r *ZkRegistry) validateZookeeperClient() error { return jerrors.Annotatef(err, "newZookeeperClient(address:%+v)", r.PrimitiveURL) } -func (r *ZkRegistry) handleZkRestart() { +func (r *zkRegistry) handleZkRestart() { var ( err error flag bool @@ -247,7 +247,7 @@ LOOP: } } -func (r *ZkRegistry) Register(conf common.URL) error { +func (r *zkRegistry) Register(conf common.URL) error { var ( ok bool err error @@ -308,7 +308,7 @@ func (r *ZkRegistry) Register(conf common.URL) error { return nil } -func (r *ZkRegistry) register(c common.URL) error { +func (r *zkRegistry) register(c common.URL) error { var ( err error //revision string @@ -423,7 +423,7 @@ func (r *ZkRegistry) register(c common.URL) error { return nil } -func (r *ZkRegistry) registerTempZookeeperNode(root string, node string) error { +func (r *zkRegistry) registerTempZookeeperNode(root string, node string) error { var ( err error zkPath string @@ -446,12 +446,12 @@ func (r *ZkRegistry) registerTempZookeeperNode(root string, node string) error { return nil } -func (r *ZkRegistry) Subscribe(conf common.URL) (registry.Listener, error) { +func (r *zkRegistry) Subscribe(conf common.URL) (registry.Listener, error) { r.wg.Add(1) return r.getListener(conf) } -func (r *ZkRegistry) getListener(conf common.URL) (*zkEventListener, error) { +func (r *zkRegistry) getListener(conf common.URL) (*zkEventListener, error) { var ( zkListener *zkEventListener ) @@ -489,7 +489,7 @@ func (r *ZkRegistry) getListener(conf common.URL) (*zkEventListener, error) { return zkListener, nil } -func (r *ZkRegistry) closeRegisters() { +func (r *zkRegistry) closeRegisters() { r.cltLock.Lock() defer r.cltLock.Unlock() log.Info("begin to close provider zk client") @@ -499,7 +499,7 @@ func (r *ZkRegistry) closeRegisters() { r.services = nil } -func (r *ZkRegistry) IsAvailable() bool { +func (r *zkRegistry) IsAvailable() bool { select { case <-r.done: return false diff --git a/registry/zookeeper/registry_test.go b/registry/zookeeper/registry_test.go index 0f8351f1bc9f1de47b6551620d06102c3af5f647..2853e670caab70b45239a8c8779168ab9865c54a 100644 --- a/registry/zookeeper/registry_test.go +++ b/registry/zookeeper/registry_test.go @@ -18,7 +18,7 @@ func Test_Register(t *testing.T) { regurl, _ := common.NewURL(context.TODO(), "registry://127.0.0.1:1111", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))) url, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithMethods([]string{"GetUser", "AddUser"})) - ts, reg, err := NewMockZkRegistry(®url) + ts, reg, err := newMockZkRegistry(®url) defer ts.Stop() err = reg.Register(url) children, _ := reg.client.getChildren("/dubbo/com.ikurento.user.UserProvider/providers") @@ -29,7 +29,7 @@ func Test_Register(t *testing.T) { func Test_Subscribe(t *testing.T) { regurl, _ := common.NewURL(context.TODO(), "registry://127.0.0.1:1111", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))) url, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithMethods([]string{"GetUser", "AddUser"})) - ts, reg, err := NewMockZkRegistry(®url) + ts, reg, err := newMockZkRegistry(®url) defer ts.Stop() //provider register @@ -42,7 +42,7 @@ func Test_Subscribe(t *testing.T) { //consumer register regurl.Params.Set(constant.ROLE_KEY, strconv.Itoa(common.CONSUMER)) - _, reg2, err := NewMockZkRegistry(®url) + _, reg2, err := newMockZkRegistry(®url) reg2.client = reg.client err = reg2.Register(url) listener, err := reg2.Subscribe(url) @@ -60,7 +60,7 @@ func Test_ConsumerDestory(t *testing.T) { regurl, _ := common.NewURL(context.TODO(), "registry://127.0.0.1:1111", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.CONSUMER))) url, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithMethods([]string{"GetUser", "AddUser"})) - ts, reg, err := NewMockZkRegistry(®url) + ts, reg, err := newMockZkRegistry(®url) defer ts.Stop() assert.NoError(t, err) @@ -80,7 +80,7 @@ func Test_ProviderDestory(t *testing.T) { regurl, _ := common.NewURL(context.TODO(), "registry://127.0.0.1:1111", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))) url, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithMethods([]string{"GetUser", "AddUser"})) - ts, reg, err := NewMockZkRegistry(®url) + ts, reg, err := newMockZkRegistry(®url) defer ts.Stop() assert.NoError(t, err)