Version: v0.11.1 Latest Latest

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

Go to latest
Published: Oct 26, 2015 License: MPL-2.0 Imports: 9 Imported by: 0




This section is empty.


This section is empty.


func StringToWaitDurationHookFunc added in v0.11.1

func StringToWaitDurationHookFunc() mapstructure.DecodeHookFunc

StringToWaitDurationHookFunc returns a function that converts strings to wait value. This is designed to be used with mapstructure for parsing out a wait value.


type RetryFunc

type RetryFunc func(time.Duration) time.Duration

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.

var DefaultRetryFunc RetryFunc = func(t time.Duration) time.Duration {
	return t

DefaultRetryFunc is the default return function, which just echos whatever duration it was given.

type View

type View struct {
	// Dependency is the dependency that is associated with this View
	Dependency dep.Dependency

	// Data is the most-recently-received data from Consul for this View
	Data         interface{}
	ReceivedData bool
	LastIndex    uint64
	// 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.

type Wait

type Wait struct {
	// Min and Max are the minimum and maximum time, respectively, to wait for
	// data changes before rendering a new template to disk.
	Min time.Duration `json:"min" mapstructure:"min"`
	Max time.Duration `json:"max" mapstructure:"max"`

Wait is the Min/Max duration used by the Watcher

func ParseWait

func ParseWait(s string) (*Wait, error)

ParseWait parses a string of the format `minimum(:maximum)` into a Wait struct.

type WaitVar added in v0.7.0

type WaitVar Wait

WaitVar implements the Flag.Value interface and allows the user to specify a watch interval using Go's flag parsing library.

func (*WaitVar) Set added in v0.7.0

func (w *WaitVar) Set(value string) error

Set sets the value in the format min[:max] for a wait timer.

func (*WaitVar) String added in v0.7.0

func (w *WaitVar) String() string

String returns the string format for this wait variable

type Watcher

type Watcher struct {

	// 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

	// FinishCh is the chan where the watcher reports it is "done".
	FinishCh chan struct{}
	// 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) 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.

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.

Jump to

Keyboard shortcuts

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