Add watch options
This commit is contained in:
parent
9f8754df75
commit
b2de9ebfd0
8
mdns.go
8
mdns.go
@ -297,8 +297,14 @@ func (m *mdnsRegistry) ListServices() ([]*registry.Service, error) {
|
|||||||
return services, nil
|
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{
|
md := &mdnsWatcher{
|
||||||
|
wo: wo,
|
||||||
ch: make(chan *mdns.ServiceEntry, 32),
|
ch: make(chan *mdns.ServiceEntry, 32),
|
||||||
exit: make(chan struct{}),
|
exit: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type mdnsWatcher struct {
|
type mdnsWatcher struct {
|
||||||
|
wo registry.WatchOptions
|
||||||
ch chan *mdns.ServiceEntry
|
ch chan *mdns.ServiceEntry
|
||||||
exit chan struct{}
|
exit chan struct{}
|
||||||
}
|
}
|
||||||
@ -26,6 +27,12 @@ func (m *mdnsWatcher) Next() (*registry.Result, error) {
|
|||||||
continue
|
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
|
var action string
|
||||||
|
|
||||||
if e.TTL == 0 {
|
if e.TTL == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user