Simplified delService code; properly delete service nodes

This commit is contained in:
Milos Gajdos 2019-06-18 21:39:00 +01:00
parent 7266c62d09
commit c0a628d65b
No known key found for this signature in database
GPG Key ID: 8B31058CC55DFD4F

View File

@ -115,27 +115,20 @@ func delNodes(old, del []*registry.Node) []*registry.Node {
func delServices(old, del []*registry.Service) []*registry.Service {
var services []*registry.Service
for _, o := range old {
srv := new(registry.Service)
*srv = *o
var rem bool
for _, s := range del {
if srv.Version == s.Version {
srv.Nodes = delNodes(srv.Nodes, s.Nodes)
if len(srv.Nodes) == 0 {
if o.Version == s.Version {
s.Nodes = delNodes(s.Nodes, o.Nodes)
if len(s.Nodes) == 0 {
rem = true
break
}
}
}
if !rem {
services = append(services, srv)
services = append(services, o)
}
}
return services
}