Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RetryFunc ¶
RetryFunc is a function that defines the retry for a given watcher. The function parameter is the current retry (which might be nil), and the return value is the new retry. In this way, you can build complex retry functions that are based off the previous values.
type View ¶
type View struct { // Dependency is the dependency that is associated with this View Dependency dep.Dependency // contains filtered or unexported fields }
View is a representation of a Dependency and the most recent data it has received from Consul.
func NewView ¶
func NewView(config *WatcherConfig, d dep.Dependency) (*View, error)
NewView creates a new view object from the given Consul API client and Dependency. If an error occurs, it will be returned.
func (*View) Data ¶
func (v *View) Data() interface{}
Data returns the most-recently-received data from Consul for this View.
func (*View) DataAndLastIndex ¶ added in v0.15.0
DataAndLastIndex returns the most-recently-received data from Consul for this view, along with the last index. This is atomic so you will get the index that goes with the data you are fetching.
type Watcher ¶
type Watcher struct { sync.Mutex // DataCh is the chan where Views will be published. DataCh chan *View // ErrCh is the chan where any errors will be published. ErrCh chan error // contains filtered or unexported fields }
Watcher is a top-level manager for views that poll Consul for data.
func NewWatcher ¶
func NewWatcher(config *WatcherConfig) (*Watcher, error)
NewWatcher creates a new watcher using the given API client.
func (*Watcher) Add ¶ added in v0.6.0
func (w *Watcher) Add(d dep.Dependency) (bool, error)
Add adds the given dependency to the list of monitored depedencies and start the associated view. If the dependency already exists, no action is taken.
If the Dependency already existed, it this function will return false. If the view was successfully created, it will return true. If an error occurs while creating the view, it will be returned here (but future errors returned by the view will happen on the channel).
func (*Watcher) ForceWatching ¶ added in v0.12.0
func (w *Watcher) ForceWatching(d dep.Dependency, enabled bool)
ForceWatching is used to force setting the internal state of watching a depedency. This is only used for unit testing purposes.
func (*Watcher) Remove ¶ added in v0.6.0
func (w *Watcher) Remove(d dep.Dependency) bool
Remove removes the given dependency from the list and stops the associated View. If a View for the given dependency does not exist, this function will return false. If the View does exist, this function will return true upon successful deletion.
type WatcherConfig ¶ added in v0.6.5
type WatcherConfig struct { // Client is the mechanism for communicating with the Consul API. Clients *dep.ClientSet // Once is used to determine if the views should poll for data exactly once. Once bool // MaxStale is the maximum staleness of a query. If specified, Consul will // distribute work among all servers instead of just the leader. Specifying // this option assumes the use of AllowStale. MaxStale time.Duration // RetryFunc is a RetryFunc that represents the way retrys and backoffs // should occur. RetryFunc RetryFunc // RenewVault determines if the watcher should renew the Vault token as a // background job. RenewVault bool }
WatcherConfig is the configuration for a particular Watcher.