NewDNSWatcher creates a new DNS watcher and returns a service that is wrapping it.
(address string, dnsLookupPeriod time.Duration, notifications DNSNotifications)
| 28 | |
| 29 | // NewDNSWatcher creates a new DNS watcher and returns a service that is wrapping it. |
| 30 | func NewDNSWatcher(address string, dnsLookupPeriod time.Duration, notifications DNSNotifications) (services.Service, error) { |
| 31 | resolver, err := grpcutil.NewDNSResolverWithFreq(dnsLookupPeriod, util_log.Logger) |
| 32 | if err != nil { |
| 33 | return nil, err |
| 34 | } |
| 35 | |
| 36 | watcher, err := resolver.Resolve(address, "") |
| 37 | if err != nil { |
| 38 | return nil, err |
| 39 | } |
| 40 | |
| 41 | w := &dnsWatcher{ |
| 42 | watcher: watcher, |
| 43 | notifications: notifications, |
| 44 | } |
| 45 | return services.NewBasicService(nil, w.watchDNSLoop, nil), nil |
| 46 | } |
| 47 | |
| 48 | // watchDNSLoop watches for changes in DNS and sends notifications. |
| 49 | func (w *dnsWatcher) watchDNSLoop(servCtx context.Context) error { |
no test coverage detected