Documentation ¶
Overview ¶
Package etcdutil provides a helper structure that simplifies common etcd operations. The *Get* operations return a uint64 which is the etcd index that can be used as a wait index.
Index ¶
- type EtcdUtil
- func (u *EtcdUtil) Client() *etcd.Client
- func (u *EtcdUtil) Close()
- func (u *EtcdUtil) Get(key, def string) (string, uint64, error)
- func (u *EtcdUtil) GetDuration(key string, def time.Duration) (time.Duration, uint64, error)
- func (u *EtcdUtil) GetInt(key string, def int) (int, uint64, error)
- func (u *EtcdUtil) GetJSON(key string, dst interface{}) (uint64, error)
- func (u *EtcdUtil) MustGet(key string) (string, uint64)
- func (u *EtcdUtil) MustGetDuration(key string) (time.Duration, uint64)
- func (u *EtcdUtil) MustGetInt(key string) (int, uint64)
- func (u *EtcdUtil) MustGetJSON(key string, dst interface{}) uint64
- func (u *EtcdUtil) Walk(key string, sorted bool, f func(key, value string) error) (uint64, error)
- func (u *EtcdUtil) Watch(key string, waitIndex uint64, recursive bool, f func(key, value string))
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EtcdUtil ¶
type EtcdUtil struct {
// contains filtered or unexported fields
}
EtcdUtil is the primary structure used in the package. Instantiate it with New or NewFromString.
func New ¶
New creates a utilitiy structure that connects to etcd on the following machines. The prefix will be prepended to all keys during any requests.
func NewFromString ¶
NewFromString is like new, but takes a comman separated list of machines instead of an array.
func (*EtcdUtil) Close ¶
func (u *EtcdUtil) Close()
Close closes the etcd client and stops any watches.
func (*EtcdUtil) GetDuration ¶
GetDuration is like Get but returns a duration.
func (*EtcdUtil) MustGetDuration ¶
MustGetDuration is like MustGet but returns a duration.
func (*EtcdUtil) MustGetInt ¶
MustGetInt is like MustGet but returns an integer.
func (*EtcdUtil) MustGetJSON ¶
MustGetJSON is like MustGet but decodes the JSON to dst.
func (*EtcdUtil) Walk ¶
Walk gets all the values under prefix+key and calls f on each key/value pair. If sorted is true, calls to f will be done in order of the key. If f returns an error, walking is halted and the error returned.
func (*EtcdUtil) Watch ¶
Watch watches for any changes to the given prefix+key. If recursive is true, any changes to that directory or any sub-directory are also watched. Whenever a change is received, the given function will be called for the changed key and the changed value.
Using the value 0 for the waitIndex only returns new changes. Otherwise, you probably want it to be a value returned by one of the *Get* commands.
Watching will continue to retry until Close() is called. Multiple Watch's may be started.