Skip to content
Snippets Groups Projects
Commit 01e16d78 authored by vito.he's avatar vito.he
Browse files

Mod:some struct and func to lowercase

parent 62cc50a4
No related branches found
No related tags found
No related merge requests found
......@@ -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{}
}
......
......@@ -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 &registryAwareCluster{}
}
......
......@@ -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{}
}
......
......@@ -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 &registryProtocol{
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 {
......
......@@ -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)
......
......@@ -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,
......
......@@ -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
......
......@@ -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(&regurl)
ts, reg, err := newMockZkRegistry(&regurl)
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(&regurl)
ts, reg, err := newMockZkRegistry(&regurl)
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(&regurl)
_, reg2, err := newMockZkRegistry(&regurl)
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(&regurl)
ts, reg, err := newMockZkRegistry(&regurl)
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(&regurl)
ts, reg, err := newMockZkRegistry(&regurl)
defer ts.Stop()
assert.NoError(t, 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