Documentation
¶
Index ¶
- Constants
- func GetKeys(pairs []Pair) []string
- type Config
- type ConsulClient
- func (c *ConsulClient) Acquire(ctx context.Context, sessionID string, key string, value []byte) (bool, error)
- func (c *ConsulClient) DeleteTree(ctx context.Context, key string) error
- func (c *ConsulClient) Deregister(ctx context.Context, sessionID string) error
- func (c *ConsulClient) Exists(ctx context.Context, key string) (bool, error)
- func (c *ConsulClient) Get(ctx context.Context, key string) (*Pair, error)
- func (c *ConsulClient) IsAlive(_ context.Context) (bool, error)
- func (c *ConsulClient) IsRegistered(ctx context.Context, sessionID string) bool
- func (c *ConsulClient) List(ctx context.Context, prefix string) ([]Pair, error)
- func (c *ConsulClient) ListKeys(ctx context.Context, key string) ([]string, error)
- func (c *ConsulClient) Put(ctx context.Context, key string, value []byte) (string, error)
- func (c *ConsulClient) Register(ctx context.Context, name string, ttl time.Duration) (string, error)
- func (c *ConsulClient) Release(ctx context.Context, sessionID string, key string, value string) bool
- func (c *ConsulClient) Renew(ctx context.Context, sessionID string) error
- func (c *ConsulClient) RenewPeriodic(ctx context.Context, sessionID string, ttl time.Duration, ...) error
- func (c *ConsulClient) Watch(ctx context.Context, wh *WatchConfig) (IWatcher, error)
- type ConsulConfig
- type ConsulWatcher
- type HandlerFunc
- type IRegistry
- type IWatcher
- type Pair
- type WatchConfig
Constants ¶
const (
// Consul constant for getting ConsulClient from Registry factory
Consul = "consul"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { Driver string ConsulConfig ConsulConfig }
Config holds registry configuration
type ConsulClient ¶
type ConsulClient struct {
// contains filtered or unexported fields
}
ConsulClient ...
func (*ConsulClient) Acquire ¶
func (c *ConsulClient) Acquire(ctx context.Context, sessionID string, key string, value []byte) (bool, error)
Acquire a lock
func (*ConsulClient) DeleteTree ¶
func (c *ConsulClient) DeleteTree(ctx context.Context, key string) error
DeleteTree deletes all keys under a prefix
func (*ConsulClient) Deregister ¶
func (c *ConsulClient) Deregister(ctx context.Context, sessionID string) error
Deregister node, destroy consul session
func (*ConsulClient) IsAlive ¶
func (c *ConsulClient) IsAlive(_ context.Context) (bool, error)
IsAlive checks the health of the consul
func (*ConsulClient) IsRegistered ¶
func (c *ConsulClient) IsRegistered(ctx context.Context, sessionID string) bool
IsRegistered is used checking the registration status
func (*ConsulClient) Register ¶
func (c *ConsulClient) Register(ctx context.Context, name string, ttl time.Duration) (string, error)
Register is used for node registration which creates a session to consul
func (*ConsulClient) Release ¶
func (c *ConsulClient) Release(ctx context.Context, sessionID string, key string, value string) bool
Release a lock
func (*ConsulClient) Renew ¶
func (c *ConsulClient) Renew(ctx context.Context, sessionID string) error
Renew renews consul session
func (*ConsulClient) RenewPeriodic ¶
func (c *ConsulClient) RenewPeriodic(ctx context.Context, sessionID string, ttl time.Duration, doneCh <-chan struct{}) error
RenewPeriodic renews consul session periodically until doneCh signals done
func (*ConsulClient) Watch ¶
func (c *ConsulClient) Watch(ctx context.Context, wh *WatchConfig) (IWatcher, error)
Watch watches a key and returns a watcher instance, this instance should be used to terminate the watch
type ConsulWatcher ¶
type ConsulWatcher struct { Config *WatchConfig // contains filtered or unexported fields }
ConsulWatcher implements consul watch handler and stores the users handler function
func (*ConsulWatcher) StartWatch ¶
func (cwh *ConsulWatcher) StartWatch() error
StartWatch will start the watch
func (*ConsulWatcher) StopWatch ¶
func (cwh *ConsulWatcher) StopWatch()
StopWatch will cleanup the active consul watches
type HandlerFunc ¶
HandlerFunc provides interface for the watch handler func which is implemented by watch subscriber
type IRegistry ¶
type IRegistry interface { // Register a node with the Registry with a given name // Returns a Registration id or error Register(ctx context.Context, name string, ttl time.Duration) (string, error) // Deregister a node which was registered with a id // Returns error on failure Deregister(ctx context.Context, id string) error // IsRegistered checks is node with registration_id is registred with registry IsRegistered(ctx context.Context, id string) bool // Renew a registration using registration_id Renew(ctx context.Context, id string) error // RenewPeriodic renews a registration id periodically based on TTL RenewPeriodic(ctx context.Context, id string, ttl time.Duration, doneCh <-chan struct{}) error // Acquire a lock for a registration_id on a given key and value pair Acquire(ctx context.Context, id string, key string, value []byte) (bool, error) // Release a lock for a registration_id on a given key and value pair Release(ctx context.Context, id string, key string, value string) bool // Watch on a key/keyprefix in registry Watch(ctx context.Context, wh *WatchConfig) (IWatcher, error) // Put a key value pair Put(ctx context.Context, key string, value []byte) (string, error) // Get returns a value for a key Get(ctx context.Context, key string) (*Pair, error) // List returns a keys with matching key prefix ListKeys(ctx context.Context, prefix string) ([]string, error) // List returns a slice of pairs with matching key prefix List(ctx context.Context, prefix string) ([]Pair, error) // Exists checks the existence of a key Exists(ctx context.Context, key string) (bool, error) // DeleteTree deletes all keys under a prefix DeleteTree(ctx context.Context, key string) error // IsAlive checks the health of the registry IsAlive(context.Context) (bool, error) }
IRegistry implements a generic interface for service discovery
func NewConsulClient ¶
func NewConsulClient(config *ConsulConfig) (IRegistry, error)
NewConsulClient creates a new consul client
func NewRegistry ¶
NewRegistry initializes the registry instance based on Config
type IWatcher ¶
type IWatcher interface { // StartWatch interface implemented by registry watcher to start a watch StartWatch() error // StopWatch interface implemented by registry watcher to stop a watch // it should also release the resources held StopWatch() }
IWatcher defines the watch interface for watch over registry
func NewConsulWatcher ¶
func NewConsulWatcher(ctx context.Context, watchConfig *WatchConfig, plan *watch.Plan, client *api.Client) IWatcher
NewConsulWatcher is used to create a new struct of type WatchHandler
type Pair ¶
type Pair struct { Key string Value []byte // Version - The version of the stored key-value pair // Set by the registry, ModifyIndex in case of consul Version string SessionID string }
Pair is the registry struct returned to watch handler
type WatchConfig ¶
type WatchConfig struct { WatchType string WatchPath string Handler HandlerFunc }
WatchConfig struct provides watch details on registry