fix: consul lint error (#1530)

* fix: consul lint error

* fix: services init eroor
pull/1535/head
Tt yo 3 years ago committed by GitHub
parent 5e88a20cd4
commit 3b477e7e52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      contrib/registry/consul/client.go
  2. 8
      contrib/registry/consul/registry.go
  3. 6
      contrib/registry/consul/watcher.go
  4. 1
      hack/.lintcheck_failures

@ -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
}

@ -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,
}

@ -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
}

@ -1,4 +1,3 @@
./contrib/registry/nacos
./contrib/registry/consul
./contrib/registry/kubernetes
./contrib/registry/zookeeper

Loading…
Cancel
Save