diff --git a/contrib/registry/consul/client.go b/contrib/registry/consul/client.go index aec2b5faa..cad32aaa5 100644 --- a/contrib/registry/consul/client.go +++ b/contrib/registry/consul/client.go @@ -37,7 +37,9 @@ func (d *Client) Service(ctx context.Context, service string, index uint64, pass if err != nil { return nil, 0, err } - var services []*registry.ServiceInstance + + services := make([]*registry.ServiceInstance, 0) + for _, entry := range entries { var version string for _, tag := range entry.Service.Tags { @@ -111,7 +113,7 @@ func (d *Client) Register(ctx context.Context, svc *registry.ServiceInstance, en for { select { case <-ticker.C: - d.cli.Agent().UpdateTTL("service:"+svc.ID, "pass", "pass") + _ = d.cli.Agent().UpdateTTL("service:"+svc.ID, "pass", "pass") case <-d.ctx.Done(): return } diff --git a/contrib/registry/consul/registry.go b/contrib/registry/consul/registry.go index f3c87abd2..d2348b902 100644 --- a/contrib/registry/consul/registry.go +++ b/contrib/registry/consul/registry.go @@ -33,12 +33,10 @@ type Config struct { // Registry is consul registry type Registry struct { - cfg *Config cli *Client enableHealthCheck bool - - registry map[string]*serviceSet - lock sync.RWMutex + registry map[string]*serviceSet + lock sync.RWMutex } // New creates consul registry @@ -104,7 +102,7 @@ func (r *Registry) Watch(ctx context.Context, name string) (registry.Watcher, er set, ok := r.registry[name] if !ok { set = &serviceSet{ - watcher: make(map[*watcher]struct{}, 0), + watcher: make(map[*watcher]struct{}), services: &atomic.Value{}, serviceName: name, } diff --git a/contrib/registry/consul/watcher.go b/contrib/registry/consul/watcher.go index 33693da7a..3b4bfece8 100644 --- a/contrib/registry/consul/watcher.go +++ b/contrib/registry/consul/watcher.go @@ -21,11 +21,11 @@ func (w *watcher) Next() (services []*registry.ServiceInstance, err error) { err = w.ctx.Err() case <-w.event: } + ss, ok := w.set.services.Load().([]*registry.ServiceInstance) + if ok { - for _, s := range ss { - services = append(services, s) - } + services = append(services, ss...) } return } diff --git a/hack/.lintcheck_failures b/hack/.lintcheck_failures index 037e60443..803889622 100644 --- a/hack/.lintcheck_failures +++ b/hack/.lintcheck_failures @@ -1,4 +1,3 @@ ./contrib/registry/nacos -./contrib/registry/consul ./contrib/registry/kubernetes ./contrib/registry/zookeeper