consul

package
v2.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2019 License: Apache-2.0 Imports: 14 Imported by: 17

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultPlugin = *NewPlugin()

DefaultPlugin is a default instance of Plugin.

Functions

func ConfigToClient

func ConfigToClient(cfg *Config) (*api.Config, error)

ConfigToClient transforms Config into api.Config, which is ready for use with underlying consul package.

Types

type BrokerWatcher

type BrokerWatcher struct {
	*Client
	// contains filtered or unexported fields
}

BrokerWatcher uses Client to access the datastore. The connection can be shared among multiple BrokerWatcher. In case of accessing a particular subtree in Consul only, BrokerWatcher allows defining a keyPrefix that is prepended to all keys in its methods in order to shorten keys used in arguments.

func (*BrokerWatcher) Delete

func (pdb *BrokerWatcher) Delete(key string, opts ...datasync.DelOption) (existed bool, err error)

Delete calls 'Delete' function of the underlying BytesConnectionEtcd. KeyPrefix defined in constructor is prepended to the key argument.

func (*BrokerWatcher) GetValue

func (pdb *BrokerWatcher) GetValue(key string) (data []byte, found bool, revision int64, err error)

GetValue calls 'GetValue' function of the underlying BytesConnectionEtcd. KeyPrefix defined in constructor is prepended to the key argument.

func (*BrokerWatcher) ListKeys

func (pdb *BrokerWatcher) ListKeys(prefix string) (keyval.BytesKeyIterator, error)

ListKeys calls 'ListKeys' function of the underlying BytesConnectionEtcd. KeyPrefix defined in constructor is prepended to the argument.

func (*BrokerWatcher) ListValues

func (pdb *BrokerWatcher) ListValues(key string) (keyval.BytesKeyValIterator, error)

ListValues calls 'ListValues' function of the underlying BytesConnectionEtcd. KeyPrefix defined in constructor is prepended to the key argument. The prefix is removed from the keys of the returned values.

func (*BrokerWatcher) NewTxn

func (pdb *BrokerWatcher) NewTxn() keyval.BytesTxn

NewTxn creates a new transaction. KeyPrefix defined in constructor will be prepended to all key arguments in the transaction.

func (*BrokerWatcher) Put

func (pdb *BrokerWatcher) Put(key string, data []byte, opts ...datasync.PutOption) error

Put calls 'Put' function of the underlying BytesConnectionEtcd. KeyPrefix defined in constructor is prepended to the key argument.

func (*BrokerWatcher) Watch

func (pdb *BrokerWatcher) Watch(resp func(keyval.BytesWatchResp), closeChan chan string, keys ...string) error

Watch starts subscription for changes associated with the selected <keys>. KeyPrefix defined in constructor is prepended to all <keys> in the argument list. The prefix is removed from the keys returned in watch events. Watch events will be delivered to <resp> callback.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client serves as a client for Consul KV storage and implements keyval.CoreBrokerWatcher interface.

func NewClient

func NewClient(cfg *api.Config) (store *Client, err error)

NewClient creates new client for Consul using given address.

func (*Client) Close

func (c *Client) Close() error

Close returns nil.

func (*Client) Delete

func (c *Client) Delete(key string, opts ...datasync.DelOption) (existed bool, err error)

Delete deletes given key.

func (*Client) GetValue

func (c *Client) GetValue(key string) (data []byte, found bool, revision int64, err error)

GetValue returns data for the given key.

func (*Client) ListKeys

func (c *Client) ListKeys(prefix string) (keyval.BytesKeyIterator, error)

ListKeys returns interator with keys for given key prefix.

func (*Client) ListValues

func (c *Client) ListValues(key string) (keyval.BytesKeyValIterator, error)

ListValues returns interator with key-value pairs for given key prefix.

func (*Client) NewBroker

func (c *Client) NewBroker(prefix string) keyval.BytesBroker

NewBroker creates a new instance of a proxy that provides access to etcd. The proxy will reuse the connection from Client. <prefix> will be prepended to the key argument in all calls from the created BrokerWatcher. To avoid using a prefix, pass keyval. Root constant as an argument.

func (*Client) NewTxn

func (c *Client) NewTxn() keyval.BytesTxn

NewTxn creates new transaction.

func (*Client) NewWatcher

func (c *Client) NewWatcher(prefix string) keyval.BytesWatcher

NewWatcher creates a new instance of a proxy that provides access to etcd. The proxy will reuse the connection from Client. <prefix> will be prepended to the key argument in all calls on created BrokerWatcher. To avoid using a prefix, pass keyval. Root constant as an argument.

func (*Client) Put

func (c *Client) Put(key string, data []byte, opts ...datasync.PutOption) error

Put stores given data for the key.

func (*Client) Watch

func (c *Client) Watch(resp func(keyval.BytesWatchResp), closeChan chan string, keys ...string) error

Watch watches given list of key prefixes.

type Config

type Config struct {
	Address         string `json:"address"`
	ReconnectResync bool   `json:"resync-after-reconnect"`
}

Config represents configuration for Consul plugin.

type Deps

type Deps struct {
	infra.PluginDeps
	StatusCheck statuscheck.PluginStatusWriter
	Resync      *resync.Plugin
}

Deps lists dependencies of the Consul plugin. If injected, Consul plugin will use StatusCheck to signal the connection status.

type Option added in v1.5.0

type Option func(*Plugin)

Option is a function that can be used in NewPlugin to customize Plugin.

func UseConf added in v1.5.0

func UseConf(conf Config) Option

UseConf returns Option which injects a particular configuration.

func UseDeps added in v1.5.0

func UseDeps(cb func(*Deps)) Option

UseDeps returns Option that can inject custom dependencies.

type Plugin

type Plugin struct {
	Deps

	*Config
	// contains filtered or unexported fields
}

Plugin implements Consul as plugin.

func NewPlugin added in v1.5.0

func NewPlugin(opts ...Option) *Plugin

NewPlugin creates a new Plugin with the provided Options.

func (*Plugin) Close

func (p *Plugin) Close() error

Close closes Consul plugin.

func (*Plugin) Disabled

func (p *Plugin) Disabled() bool

Disabled returns *true* if the plugin is not in use due to missing configuration.

func (*Plugin) Init

func (p *Plugin) Init() (err error)

Init initializes Consul plugin.

func (*Plugin) NewBroker

func (p *Plugin) NewBroker(keyPrefix string) keyval.ProtoBroker

NewBroker creates new instance of prefixed broker that provides API with arguments of type proto.Message.

func (*Plugin) NewWatcher

func (p *Plugin) NewWatcher(keyPrefix string) keyval.ProtoWatcher

NewWatcher creates new instance of prefixed broker that provides API with arguments of type proto.Message.

func (*Plugin) OnConnect added in v1.5.0

func (p *Plugin) OnConnect(callback func() error)

OnConnect executes callback from datasync

Jump to

Keyboard shortcuts

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