registry/etcd: add support for domain options (#1714)

This commit is contained in:
ben-toogood
2020-06-19 14:58:16 +01:00
committed by GitHub
parent 5f9c3a6efd
commit 87543b2c8a
2 changed files with 163 additions and 53 deletions

View File

@@ -21,6 +21,9 @@ func newEtcdWatcher(r *etcdRegistry, timeout time.Duration, opts ...registry.Wat
for _, o := range opts {
o(&wo)
}
if len(wo.Domain) == 0 {
wo.Domain = defaultDomain
}
ctx, cancel := context.WithCancel(context.Background())
stop := make(chan bool, 1)
@@ -31,8 +34,13 @@ func newEtcdWatcher(r *etcdRegistry, timeout time.Duration, opts ...registry.Wat
}()
watchPath := prefix
if len(wo.Service) > 0 {
watchPath = servicePath(wo.Service) + "/"
if wo.Domain == registry.WildcardDomain {
if len(wo.Service) > 0 {
return nil, errors.New("Cannot watch a service accross domains")
}
watchPath = prefix
} else if len(wo.Service) > 0 {
watchPath = servicePath(wo.Domain, wo.Service) + "/"
}
return &etcdWatcher{