watch/watcher.go
func NewWatcher(i *NewWatcherInput) (*Watcher, error) {
	w := &Watcher{
		clients:          i.Clients,
		depViewMap:       make(map[string]*View),
		dataCh:           make(chan *View, dataBufferSize),
		errCh:            make(chan error),
		maxStale:         i.MaxStale,
		once:             i.Once,
		retryFuncConsul:  i.RetryFuncConsul,
		retryFuncDefault: i.RetryFuncDefault,
		retryFuncVault:   i.RetryFuncVault,
		vaultGrace:       i.VaultGrace,
	}

	// Start a watcher for the Vault renew if that config was specified
	if i.RenewVault {
		vt, err := dep.NewVaultTokenQuery(i.VaultToken)
		if err != nil {
			return nil, errors.Wrap(err, "watcher")
		}
		if _, err := w.Add(vt); err != nil {
			return nil, errors.Wrap(err, "watcher")
		}
	}

	if len(i.VaultAgentTokenFile) > 0 {
		vag, err := dep.NewVaultAgentTokenQuery(i.VaultAgentTokenFile)
		if err != nil {
			return nil, errors.Wrap(err, "watcher")
		}
		if _, err := w.Add(vag); err != nil {
			return nil, errors.Wrap(err, "watcher")
		}
	}

	return w, nil
}
func NewWatcher(i *NewWatcherInput) (*Watcher, error) {
	w := &Watcher{
		clients:          i.Clients,
		depViewMap:       make(map[string]*View),
		dataCh:           make(chan *View, dataBufferSize),
		errCh:            make(chan error),
		maxStale:         i.MaxStale,
		once:             i.Once,
		retryFuncConsul:  i.RetryFuncConsul,
		retryFuncDefault: i.RetryFuncDefault,
		retryFuncVault:   i.RetryFuncVault,
		vaultGrace:       i.VaultGrace,
	}

	// Start a watcher for the Vault renew if that config was specified
	if i.RenewVault {
		vt, err := dep.NewVaultTokenQuery(i.VaultToken)
		if err != nil {
			return nil, errors.Wrap(err, "watcher")
		}
		if _, err := w.Add(vt); err != nil {
			return nil, errors.Wrap(err, "watcher")
		}
	}

	if len(i.VaultAgentTokenFile) > 0 {
		vag, err := dep.NewVaultAgentTokenQuery(i.VaultAgentTokenFile)
		if err != nil {
			return nil, errors.Wrap(err, "watcher")
		}
		if _, err := w.Add(vag); err != nil {
			return nil, errors.Wrap(err, "watcher")
		}
	}

	return w, nil
}
// NewWatcher creates a new watcher using the given API client.