Skip to content
Permalink
Browse files
refactor: go fmt
  • Loading branch information
PhilYue committed Jan 23, 2022
1 parent 2432f7d commit abdc22737fbfdb64296981b8591780c5ac6cdaad
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 45 deletions.
@@ -42,9 +42,9 @@ const (
// Kind is the kind of Adapter Plugin.
Kind = constant.SpringCloudAdapter

Nacos = "nacos"
Nacos = "nacos"
Zookeeper = "zookeeper"
Consul = "consul"
Consul = "consul"
)

func init() {
@@ -128,7 +128,7 @@ func (a *CloudAdapter) Stop() {
func (a *CloudAdapter) Apply() error {
//registryUsed := ad.Config["registry"].(map[string]interface{})
var (
sd servicediscovery.ServiceDiscovery
sd servicediscovery.ServiceDiscovery
err error
)
switch strings.ToLower(a.cfg.Registry.Protocol) {
@@ -19,4 +19,4 @@ package common

const (
ZKLogDiscovery = "[ZKDiscover]"
)
)
@@ -37,18 +37,18 @@ import (
type zkAppListener struct {
servicesPath string
exit chan struct{}
svcListeners *SvcListeners
wg sync.WaitGroup
svcListeners *SvcListeners
wg sync.WaitGroup

ds *zookeeperDiscovery
}

func newZkAppListener(ds *zookeeperDiscovery) zookeeper.Listener {
return &zkAppListener{
servicesPath: ds.basePath,
exit: make(chan struct{}),
svcListeners: &SvcListeners{listeners: make(map[string]zookeeper.Listener), listenerLock: sync.Mutex{}},
ds: ds,
servicesPath: ds.basePath,
exit: make(chan struct{}),
svcListeners: &SvcListeners{listeners: make(map[string]zookeeper.Listener), listenerLock: sync.Mutex{}},
ds: ds,
}
}

@@ -142,7 +142,8 @@ func (z *zkAppListener) handleEvent(children []string) {
}
}
}
};del()
}
del()

for _, serviceName := range fetchChildren {
serviceNodePath := strings.Join([]string{z.servicesPath, serviceName}, constant.PathSlash)
@@ -33,19 +33,19 @@ import (
)

type applicationServiceListener struct {
servicePath string
serviceName string
exit chan struct{}
wg sync.WaitGroup
servicePath string
serviceName string
exit chan struct{}
wg sync.WaitGroup

ds *zookeeperDiscovery
}

func newApplicationServiceListener(path string, serviceName string, ds *zookeeperDiscovery) *applicationServiceListener {
return &applicationServiceListener{
servicePath: path,
exit: make(chan struct{}),
ds: ds,
servicePath: path,
exit: make(chan struct{}),
ds: ds,
serviceName: serviceName,
}
}
@@ -125,15 +125,17 @@ func (asl *applicationServiceListener) handleEvent(children []string) {
discovery.addServiceInstance(instanceMap[id])

Check failure on line 125 in pkg/adapter/springcloud/servicediscovery/zookeeper/service_listener.go

GitHub Actions / review

pkg/adapter/springcloud/servicediscovery/zookeeper/service_listener.go#L125

[golangci] reported by reviewdog 🐶
Error return value of `discovery.addServiceInstance` is not checked (errcheck)

Raw Output:
pkg/adapter/springcloud/servicediscovery/zookeeper/service_listener.go:125:33: Error return value of `discovery.addServiceInstance` is not checked (errcheck)
				discovery.addServiceInstance(instanceMap[id])
				                            ^
}
}
};addf()
}
addf()

delf := func() {
if delInstanceIds := Diff(children, fetchChildren); delInstanceIds != nil {
for _, id := range delInstanceIds {
discovery.delServiceInstance(instanceMap[id])

Check failure on line 134 in pkg/adapter/springcloud/servicediscovery/zookeeper/service_listener.go

GitHub Actions / review

pkg/adapter/springcloud/servicediscovery/zookeeper/service_listener.go#L134

[golangci] reported by reviewdog 🐶
Error return value of `discovery.delServiceInstance` is not checked (errcheck)

Raw Output:
pkg/adapter/springcloud/servicediscovery/zookeeper/service_listener.go:134:33: Error return value of `discovery.delServiceInstance` is not checked (errcheck)
				discovery.delServiceInstance(instanceMap[id])
				                            ^
}
}
};delf()
}
delf()
}

// Close closes this listener
@@ -37,23 +37,23 @@ import (
)

const (
ZKRootPath = "/services"
ZKName = "SpringCloud-Zookeeper"
StatUP = "UP"
MaxFailTimes = 2
ZKRootPath = "/services"
ZKName = "SpringCloud-Zookeeper"
StatUP = "UP"
MaxFailTimes = 2
DefaultTimeout = "3s"
ConnDelay = 3 * time.Second
defaultTTL = 30 * time.Second
ConnDelay = 3 * time.Second
defaultTTL = 30 * time.Second
)

type zookeeperDiscovery struct {
basePath string
targetService []string
listener servicediscovery.ServiceEventListener
instanceMapLock sync.Mutex
instanceMap map[string]*servicediscovery.ServiceInstance
zkListener map[string]zookeeper.Listener
clientFacade *BaseZkClientFacade
basePath string
targetService []string
listener servicediscovery.ServiceEventListener
instanceMapLock sync.Mutex
instanceMap map[string]*servicediscovery.ServiceInstance
zkListener map[string]zookeeper.Listener
clientFacade *BaseZkClientFacade
}

func NewZKServiceDiscovery(targetService []string, config *model.RemoteConfig, listener servicediscovery.ServiceEventListener) (servicediscovery.ServiceDiscovery, error) {
@@ -71,14 +71,14 @@ func NewZKServiceDiscovery(targetService []string, config *model.RemoteConfig, l
}

z := &zookeeperDiscovery{
basePath: ZKRootPath,
listener: listener,
targetService: targetService,
instanceMap: make(map[string]*servicediscovery.ServiceInstance),
zkListener: map[string]zookeeper.Listener{},
basePath: ZKRootPath,
listener: listener,
targetService: targetService,
instanceMap: make(map[string]*servicediscovery.ServiceInstance),
zkListener: map[string]zookeeper.Listener{},
clientFacade: &BaseZkClientFacade{
name: ZKName,
client: client,
name: ZKName,
client: client,
conf: config,
clientLock: sync.Mutex{},
wg: sync.WaitGroup{},
@@ -304,7 +304,7 @@ type SpringCloudZKInstance struct {
}

type BaseZkClientFacade struct {
name string
name string
client *gxzookeeper.ZookeeperClient
clientLock sync.Mutex
wg sync.WaitGroup
@@ -368,4 +368,4 @@ func Diff(a, b []string) (diff []string) {
}

return diff
}
}
@@ -97,4 +97,4 @@ func HandleClientRestart(r ZkClientFacade) {
return
}
}
}
}
@@ -43,7 +43,6 @@ func TestAuth(t *testing.T) {
assert.True(t, strings.Contains(string(s), "test"))
}


func TestSpringCloudZookeeper(t *testing.T) {
url := "http://localhost:8888/pixiu-springcloud-server/hi"
client := &http.Client{Timeout: 5 * time.Second}
@@ -56,4 +55,4 @@ func TestSpringCloudZookeeper(t *testing.T) {
assert.Equal(t, 200, resp.StatusCode)
s, _ := ioutil.ReadAll(resp.Body)
assert.True(t, strings.Contains(string(s), "Hello Pixiu World!"))
}
}

0 comments on commit abdc227

Please sign in to comment.