Skip to content
Snippets Groups Projects
Commit 7f87ea6f authored by lzp0412's avatar lzp0412
Browse files

coding standard

parent 0c987d33
No related branches found
No related tags found
No related merge requests found
......@@ -24,21 +24,21 @@ import (
)
type nacosListener struct {
namingClient naming_client.INamingClient
listenUrl common.URL
events chan *remoting.ConfigChangeEvent
hostMapInstance map[string]model.Instance
cacheLock sync.Mutex
done chan struct{}
subscribeParam *vo.SubscribeParam
namingClient naming_client.INamingClient
listenUrl common.URL
events chan *remoting.ConfigChangeEvent
instanceMap map[string]model.Instance
cacheLock sync.Mutex
done chan struct{}
subscribeParam *vo.SubscribeParam
}
func NewNacosListener(url common.URL, namingClient naming_client.INamingClient) (*nacosListener, error) {
listener := &nacosListener{
namingClient: namingClient,
listenUrl: url, events: make(chan *remoting.ConfigChangeEvent, 32),
hostMapInstance: map[string]model.Instance{},
done: make(chan struct{}),
instanceMap: map[string]model.Instance{},
done: make(chan struct{}),
}
err := listener.startListen()
return listener, err
......@@ -111,7 +111,7 @@ func (nl *nacosListener) Callback(services []model.SubscribeService, err error)
host := services[i].Ip + ":" + strconv.Itoa(int(services[i].Port))
instance := generateInstance(services[i])
newInstanceMap[host] = instance
if old, ok := nl.hostMapInstance[host]; !ok {
if old, ok := nl.instanceMap[host]; !ok {
//instance is not exsit in cache,add it to cache
addInstances = append(addInstances, instance)
} else {
......@@ -122,14 +122,14 @@ func (nl *nacosListener) Callback(services []model.SubscribeService, err error)
}
}
for host, inst := range nl.hostMapInstance {
for host, inst := range nl.instanceMap {
if _, ok := newInstanceMap[host]; !ok {
//cache instance is not exsit in new instance list, remove it from cache
delInstances = append(delInstances, inst)
}
}
nl.hostMapInstance = newInstanceMap
nl.instanceMap = newInstanceMap
for i := range addInstances {
newUrl := generateUrl(addInstances[i])
......
......@@ -139,7 +139,7 @@ func TestNacosRegistry_Subscribe_del(t *testing.T) {
assert.Regexp(t, ".*ServiceEvent{Action{add}.*", serviceEvent2.String())
nacosReg := reg.(*nacosRegistry)
//手动注销实例
//deregister instance to mock instance offline
nacosReg.namingClient.DeregisterInstance(vo.DeregisterInstanceParam{Ip: "127.0.0.2", Port: 20000, ServiceName: "providers:com.ikurento.user.UserProvider:1.0.0:guangzhou-idc"})
serviceEvent3, _ := listener.Next()
......
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