Version: v0.27.2 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2021 License: MPL-2.0 Imports: 8 Imported by: 82




This section is empty.


This section is empty.


This section is empty.


type NewViewInput added in v0.18.0

type NewViewInput struct {
	// Dependency is the dependency to associate with the new view.
	Dependency dep.Dependency

	// Clients is the list of clients to communicate upstream. This is passed
	// directly to the dependency.
	Clients *dep.ClientSet

	// BlockQueryWaitTime is amount of time in seconds to do a blocking query for
	BlockQueryWaitTime time.Duration

	// MaxStale is the maximum amount a time a query response is allowed to be
	// stale before forcing a read from the leader.
	MaxStale time.Duration

	// Once indicates this view should poll for data exactly one time.
	Once bool

	// RetryFunc is a function which dictates how this view should retry on
	// upstream errors.
	RetryFunc RetryFunc

NewViewInput is used as input to the NewView function.

type NewWatcherInput added in v0.18.0

type NewWatcherInput struct {
	// Clients is the client set to communicate with upstreams.
	Clients *dep.ClientSet

	// MaxStale is the maximum staleness of a query.
	MaxStale time.Duration

	// Once specifies this watcher should tell views to poll exactly once.
	Once bool

	// WaitTime is amount of time in seconds to do a blocking query for
	BlockQueryWaitTime time.Duration

	// RenewVault indicates if this watcher should renew Vault tokens.
	RenewVault bool

	// VaultToken is the vault token to renew.
	VaultToken string

	// VaultAgentTokenFile is the path to Vault Agent token file
	VaultAgentTokenFile string

	// RetryFuncs specify the different ways to retry based on the upstream.
	RetryFuncConsul  RetryFunc
	RetryFuncDefault RetryFunc
	RetryFuncVault   RetryFunc

type RetryFunc

type RetryFunc func(int) (bool, time.Duration)

type View

type View struct {
	// 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(i *NewViewInput) (*View, error)

NewView constructs a new view with the given inputs.

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

func (v *View) DataAndLastIndex() (interface{}, uint64)

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.

func (*View) Dependency

func (v *View) Dependency() dep.Dependency

Dependency returns the dependency attached to this View.

type Watcher

type Watcher struct {
	// contains filtered or unexported fields

Watcher is a top-level manager for views that poll Consul for data.

func NewWatcher

func NewWatcher(i *NewWatcherInput) (*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 dependencies 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) DataCh

func (w *Watcher) DataCh() <-chan *View

DataCh returns a read-only channel of Views which is populated when a view receives data from its upstream.

func (*Watcher) ErrCh

func (w *Watcher) ErrCh() <-chan error

ErrCh returns a read-only channel of errors returned by the upstream.

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 dependency. 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.

func (*Watcher) Size added in v0.8.0

func (w *Watcher) Size() int

Size returns the number of views this watcher is watching.

func (*Watcher) Stop

func (w *Watcher) Stop()

Stop halts this watcher and any currently polling views immediately. If a view was in the middle of a poll, no data will be returned.

func (*Watcher) Watching added in v0.6.0

func (w *Watcher) Watching(d dep.Dependency) bool

Watching determines if the given dependency is being watched.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL