sidekick

package module
Version: v0.0.0-...-cfa62bf Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2014 License: Apache-2.0 Imports: 6 Imported by: 0

README

sidekick is a library that will update a key in etcd periodically.

If sidekick.New() returns without an error, there will be a goroutine keeping the key refreshed in etcd.

GoDoc

Example:

hostname,err := os.Hostname()  
// comma separated list of server URLs  
etcdServers := "http://localhost:4001"  
etcdPath := "/servers/web/" + hostname  
value := "running"  
sk, _ := sidekick.New(etcdServers,etcdpath,value)  

To change the value of the key, use:

sk.Value("newValue")  

To stop updates to etcd, use:

sk.Stop()  

To change from the default key TTL or update interval use:

sk.TTL(seconds)  
sk.UpdateInterval(seconds)  

If you want a standalone utility, see the sidekicker directory.

Documentation

Index

Constants

View Source
const DefaultTTL = 10

DefaultTTL is the default time-to-live in seconds for updates to etcd

View Source
const DefaultUpdateInterval = 8

DefaultUpdateInterval is the default frequently in seconds the key will be updated until Stop() is called

Variables

View Source
var (
	ErrIntervalTooSmall = errors.New("interval must be at least 1 second")
)

Functions

This section is empty.

Types

type Sidekick

type Sidekick struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Sidekick periodically updates a key in etcd until Stop() is called

func New

func New(servers string, key string, value string) (*Sidekick, error)

New returns a Sidekick pointer if there was no error initially setting the value, and there will be a goroutine updating the value every UpdateInterval seconds until Stop() is called If a non-nil error is returned there will be no goroutine performing updates

func (*Sidekick) SetLogger

func (sk *Sidekick) SetLogger(logger *log.Logger)

SetLogger sets a logger, by default no logs are written. This is a no-op if Stop() has been called.

func (*Sidekick) Stop

func (sk *Sidekick) Stop()

Stop stops the goroutine performing updates. This is a no-op if Stop() has been called.

func (*Sidekick) TTL

func (sk *Sidekick) TTL(ttl uint64) error

TTL sets the time-to-live on every update made to etcd. This is a no-op if Stop() has been called. TODO: validation on TTL

func (*Sidekick) UpdateInterval

func (sk *Sidekick) UpdateInterval(interval uint64) error

UpdateInterval sets the update interval to the value in seconds. This is a no-op if Stop() has been called.

func (*Sidekick) Value

func (sk *Sidekick) Value(value string)

Value changes the value used and performs an update. This is a no-op if Stop() has been called.

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL