consul

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2021 License: Apache-2.0, CC-BY-SA-4.0 Imports: 9 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// DefaultWatchWaitTime is how long we block for at a
	// time to check if the watched key has changed. This
	// affects the minimum time it takes to cancel a watch.
	DefaultWatchWaitTime = 15 * time.Second

	// RenewSessionRetryMax is the number of time we should try
	// to renew the session before giving up and throwing an error
	RenewSessionRetryMax = 5

	// MaxSessionDestroyAttempts is the maximum times we will try
	// to explicitely destroy the session attached to a lock after
	// the connectivity to the store has been lost
	MaxSessionDestroyAttempts = 5
)

Variables

View Source
var (
	// ErrMultipleEndpointsUnsupported is thrown when there are
	// multiple endpoints specified for Consul
	ErrMultipleEndpointsUnsupported = errors.New("consul does not support multiple endpoints")

	// ErrSessionRenew is thrown when the session can't be
	// renewed because the Consul version does not support sessions
	ErrSessionRenew = errors.New("cannot set or renew session for ttl, unable to operate on sessions")
)

Functions

func New

func New(endpoints []string, options *store.Config) (store.Store, error)

New creates a new Consul client given a list of endpoints and optional tls config

func Register

func Register()

Register registers consul to libkv

Types

type Consul

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

Consul is the receiver type for the Store interface

func (*Consul) AtomicDelete

func (s *Consul) AtomicDelete(key string, previous *store.KVPair) (bool, error)

AtomicDelete deletes a value at "key" if the key has not been modified in the meantime, throws an error if this is the case

func (*Consul) AtomicPut

func (s *Consul) AtomicPut(key string, value []byte, previous *store.KVPair, options *store.WriteOptions) (bool, *store.KVPair, error)

AtomicPut put a value at "key" if the key has not been modified in the meantime, throws an error if this is the case

func (*Consul) Close

func (s *Consul) Close()

Close closes the client connection

func (*Consul) Delete

func (s *Consul) Delete(key string) error

Delete a value at "key"

func (*Consul) DeleteTree

func (s *Consul) DeleteTree(directory string) error

DeleteTree deletes a range of keys under a given directory

func (*Consul) Exists

func (s *Consul) Exists(key string) (bool, error)

Exists checks that the key exists inside the store

func (*Consul) Get

func (s *Consul) Get(key string) (*store.KVPair, error)

Get the value at "key", returns the last modified index to use in conjunction to CAS calls

func (*Consul) List

func (s *Consul) List(directory string) ([]*store.KVPair, error)

List child nodes of a given directory

func (*Consul) NewLock

func (s *Consul) NewLock(key string, options *store.LockOptions) (store.Locker, error)

NewLock returns a handle to a lock struct which can be used to provide mutual exclusion on a key

func (*Consul) Put

func (s *Consul) Put(key string, value []byte, opts *store.WriteOptions) error

Put a value at "key"

func (*Consul) Watch

func (s *Consul) Watch(key string, stopCh <-chan struct{}) (<-chan *store.KVPair, error)

Watch for changes on a "key" It returns a channel that will receive changes or pass on errors. Upon creation, the current value will first be sent to the channel. Providing a non-nil stopCh can be used to stop watching.

func (*Consul) WatchTree

func (s *Consul) WatchTree(directory string, stopCh <-chan struct{}) (<-chan []*store.KVPair, error)

WatchTree watches for changes on a "directory" It returns a channel that will receive changes or pass on errors. Upon creating a watch, the current childs values will be sent to the channel .Providing a non-nil stopCh can be used to stop watching.

Jump to

Keyboard shortcuts

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