Support listing full service info in etcd
This commit is contained in:
parent
fa6590f999
commit
e9dcff49e0
@ -349,7 +349,7 @@ func (e *etcdRegistry) GetService(name string) ([]*registry.Service, error) {
|
|||||||
|
|
||||||
func (e *etcdRegistry) ListServices() ([]*registry.Service, error) {
|
func (e *etcdRegistry) ListServices() ([]*registry.Service, error) {
|
||||||
var services []*registry.Service
|
var services []*registry.Service
|
||||||
nameSet := make(map[string]struct{})
|
versions := make(map[string]*registry.Service)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), e.options.Timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), e.options.Timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@ -364,13 +364,20 @@ func (e *etcdRegistry) ListServices() ([]*registry.Service, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, n := range rsp.Kvs {
|
for _, n := range rsp.Kvs {
|
||||||
if sn := decode(n.Value); sn != nil {
|
sn := decode(n.Value)
|
||||||
nameSet[sn.Name] = struct{}{}
|
if sn == nil {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
v, ok := versions[sn.Name+sn.Version]
|
||||||
|
if !ok {
|
||||||
|
versions[sn.Name+sn.Version] = sn
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
for k := range nameSet {
|
// append to service:version nodes
|
||||||
service := ®istry.Service{}
|
v.Nodes = append(v.Nodes, sn.Nodes...)
|
||||||
service.Name = k
|
}
|
||||||
|
|
||||||
|
for _, service := range versions {
|
||||||
services = append(services, service)
|
services = append(services, service)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user