Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clusterleader ¶
Clusterleader uses Consul distributed locks to elect a cluster leader
func New ¶
func New(consulClient *api.Client, key string, node string, waitTime time.Duration) (*Clusterleader, error)
New returns a new Clusterleader instance with a given consul connection
func NewWithDefaultClient ¶
NewDefaultClient uses a default Consul client (which can also be set using Consul env variables)
func (*Clusterleader) Election ¶
func (cl *Clusterleader) Election(ctx context.Context) <-chan bool
Election returns a channel that signals if we are leader or not
func (*Clusterleader) Errors ¶
func (cl *Clusterleader) Errors() <-chan error
Errors returns a channel that receives all errors
func (*Clusterleader) IsLeader ¶
func (cl *Clusterleader) IsLeader() bool
IsLeader just returns if we are leader or not
type DistributedLock ¶
type DistributedLock struct {
// contains filtered or unexported fields
}
DistributedLock describes a lock
func NewDistributedLock ¶
func NewDistributedLock(consulClient *api.Client, prefix string, sessionTTL time.Duration) (*DistributedLock, error)
NewDistributedLock returns an instance with a given Consul client
func NewDistributedLockWithDefaultClient ¶
func NewDistributedLockWithDefaultClient(prefix string, sessionTTL time.Duration) (*DistributedLock, error)
NewDistributedLockWithDefaultClient uses a Consul client with default settings (or values from ENV)
func (*DistributedLock) Lock ¶
func (dl *DistributedLock) Lock(key string, value string, lockWaitTime time.Duration) (<-chan struct{}, error)
Lock tries once to acquire the lock or return an error if it could not get it
func (*DistributedLock) Unlock ¶
func (dl *DistributedLock) Unlock(key string) error
Unlock releases a specific lock
func (*DistributedLock) UnlockAll ¶
func (dl *DistributedLock) UnlockAll()
UnlockAll releases all held locks