1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-03-17 21:07:54 +02:00

fix: consul lint error (#1530)

* fix: consul lint error

* fix: services init eroor
This commit is contained in:
Tt yo 2021-10-06 13:10:20 +08:00 committed by GitHub
parent 5e88a20cd4
commit 3b477e7e52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 11 deletions

View File

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

View File

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

View File

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

View File

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