NewResolverWithClient creates a new Resolver that uses the provided resolv.conf configuration, reload period, and Client implementation to perform DNS queries. Configuration from resolv.conf will be periodically reloaded.
(resolvConf string, logger log.Logger, reloadPeriod time.Duration, client Client)
| 69 | // reload period, and Client implementation to perform DNS queries. Configuration from resolv.conf |
| 70 | // will be periodically reloaded. |
| 71 | func NewResolverWithClient(resolvConf string, logger log.Logger, reloadPeriod time.Duration, client Client) *Resolver { |
| 72 | r := &Resolver{ |
| 73 | client: client, |
| 74 | logger: logger, |
| 75 | confPath: resolvConf, |
| 76 | reloadPeriod: reloadPeriod, |
| 77 | stop: make(chan struct{}), |
| 78 | } |
| 79 | |
| 80 | // Attempt an initial load of the configuration but fallback to defaults if it fails. The file |
| 81 | // missing should not be fatal according to `man 5 resolv.conf`. |
| 82 | if err := r.loadConfig(); err != nil { |
| 83 | level.Warn(r.logger).Log("msg", "unable to load resolv.conf, using default values", "path", r.confPath, "err", err) |
| 84 | r.conf = defaultClientConfig() |
| 85 | } |
| 86 | |
| 87 | // Attempt to reload configuration periodically. If the reloads fail, old values are used. |
| 88 | go r.loop() |
| 89 | return r |
| 90 | } |
| 91 | |
| 92 | // Stop stops periodic tasks run by the Resolver. The resolver should not be used after it is stopped. |
| 93 | func (r *Resolver) Stop() { |