From b2de9ebfd05b3098d1f1cc440f1dcb68408460f6 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 19 Feb 2018 17:12:37 +0000 Subject: [PATCH] Add watch options --- mdns.go | 8 +++++++- watcher.go | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mdns.go b/mdns.go index e06893d..1b94287 100644 --- a/mdns.go +++ b/mdns.go @@ -297,8 +297,14 @@ func (m *mdnsRegistry) ListServices() ([]*registry.Service, error) { return services, nil } -func (m *mdnsRegistry) Watch() (registry.Watcher, error) { +func (m *mdnsRegistry) Watch(opts ...registry.WatchOption) (registry.Watcher, error) { + var wo registry.WatchOptions + for _, o := range opts { + o(&wo) + } + md := &mdnsWatcher{ + wo: wo, ch: make(chan *mdns.ServiceEntry, 32), exit: make(chan struct{}), } diff --git a/watcher.go b/watcher.go index 379b40f..952816d 100644 --- a/watcher.go +++ b/watcher.go @@ -9,6 +9,7 @@ import ( ) type mdnsWatcher struct { + wo registry.WatchOptions ch chan *mdns.ServiceEntry exit chan struct{} } @@ -26,6 +27,12 @@ func (m *mdnsWatcher) Next() (*registry.Result, error) { continue } + // Filter watch options + // wo.Service: Only keep services we care about + if len(m.wo.Service) > 0 && txt.Service != m.wo.Service { + continue + } + var action string if e.TTL == 0 {