etcdutil

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 5, 2015 License: MIT Imports: 7 Imported by: 0

README

etcdutil

GoDoc

Package etcdutil provides a simple(r) interface for the most common etcd operations.

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

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

func New(machines []string, prefix string) *EtcdUtil

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

func NewFromString(machines, prefix string) *EtcdUtil

NewFromString is like new, but takes a comman separated list of machines instead of an array.

func (*EtcdUtil) Client added in v0.1.1

func (u *EtcdUtil) Client() *etcd.Client

Client returns the underlying client if there is one.

func (*EtcdUtil) Close

func (u *EtcdUtil) Close()

Close closes the etcd client and stops any watches.

func (*EtcdUtil) Get

func (u *EtcdUtil) Get(key, def string) (string, uint64, error)

Get returns the value for the given prefix+key or the default value given.

func (*EtcdUtil) GetDuration

func (u *EtcdUtil) GetDuration(key string, def time.Duration) (time.Duration, uint64, error)

GetDuration is like Get but returns a duration.

func (*EtcdUtil) GetInt

func (u *EtcdUtil) GetInt(key string, def int) (int, uint64, error)

GetInt is like Get but returns an integer.

func (*EtcdUtil) GetJSON

func (u *EtcdUtil) GetJSON(key string, dst interface{}) (uint64, error)

GetJSON is like get but decodes the JSON to dst.

func (*EtcdUtil) MustGet

func (u *EtcdUtil) MustGet(key string) (string, uint64)

MustGet is like Get but panics with the error if an error occurs.

func (*EtcdUtil) MustGetDuration

func (u *EtcdUtil) MustGetDuration(key string) (time.Duration, uint64)

MustGetDuration is like MustGet but returns a duration.

func (*EtcdUtil) MustGetInt

func (u *EtcdUtil) MustGetInt(key string) (int, uint64)

MustGetInt is like MustGet but returns an integer.

func (*EtcdUtil) MustGetJSON

func (u *EtcdUtil) MustGetJSON(key string, dst interface{}) uint64

MustGetJSON is like MustGet but decodes the JSON to dst.

func (*EtcdUtil) Walk

func (u *EtcdUtil) Walk(key string, sorted bool, f func(key, value string) error) (uint64, error)

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

func (u *EtcdUtil) Watch(key string, waitIndex uint64, recursive bool, f func(key, value string))

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.

Jump to

Keyboard shortcuts

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