Documentation ¶
Index ¶
- Variables
- type Client
- func NewClient(cfg Config, codec codec.Codec, logger log.Logger, ...) (*Client, error)
- func NewInMemoryClient(codec codec.Codec, logger log.Logger, registerer prometheus.Registerer) (*Client, io.Closer)
- func NewInMemoryClientWithConfig(codec codec.Codec, cfg Config, logger log.Logger, ...) (*Client, io.Closer)
- func (c *Client) CAS(ctx context.Context, key string, ...) error
- func (c *Client) Delete(ctx context.Context, key string) error
- func (c *Client) Get(ctx context.Context, key string) (interface{}, error)
- func (c *Client) LastUpdateTime(_ string) time.Time
- func (c *Client) List(ctx context.Context, prefix string) ([]string, error)
- func (c *Client) Put(ctx context.Context, key string, value interface{}) error
- func (c *Client) WatchKey(ctx context.Context, key string, f func(interface{}) bool)
- func (c *Client) WatchPrefix(ctx context.Context, prefix string, f func(string, interface{}) bool)
- type Config
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned by ConsulClient.Get. ErrNotFound = fmt.Errorf("Not found") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a kv.Client for Consul.
func NewClient ¶
func NewClient(cfg Config, codec codec.Codec, logger log.Logger, registerer prometheus.Registerer) (*Client, error)
NewClient returns a new Client.
func NewInMemoryClient ¶
func NewInMemoryClient(codec codec.Codec, logger log.Logger, registerer prometheus.Registerer) (*Client, io.Closer)
NewInMemoryClient makes a new mock consul client.
func NewInMemoryClientWithConfig ¶ added in v0.4.0
func NewInMemoryClientWithConfig(codec codec.Codec, cfg Config, logger log.Logger, registerer prometheus.Registerer) (*Client, io.Closer)
NewInMemoryClientWithConfig makes a new mock consul client with supplied Config.
func (*Client) CAS ¶
func (c *Client) CAS(ctx context.Context, key string, f func(in interface{}) (out interface{}, retry bool, err error)) error
CAS atomically modifies a value in a callback. If value doesn't exist you'll get nil as an argument to your callback.
func (*Client) LastUpdateTime ¶ added in v1.15.0
func (*Client) WatchKey ¶
WatchKey will watch a given key in consul for changes. When the value under said key changes, the f callback is called with the deserialised value. To construct the deserialised value, a factory function should be supplied which generates an empty struct for WatchKey to deserialise into. This function blocks until the context is cancelled or f returns false.
func (*Client) WatchPrefix ¶
WatchPrefix will watch a given prefix in Consul for new keys and changes to existing keys under that prefix. When the value under said key changes, the f callback is called with the deserialised value. Values in Consul are assumed to be JSON. This function blocks until the context is cancelled.
type Config ¶
type Config struct { Host string `yaml:"host"` ACLToken flagext.Secret `yaml:"acl_token"` HTTPClientTimeout time.Duration `yaml:"http_client_timeout"` ConsistentReads bool `yaml:"consistent_reads"` WatchKeyRateLimit float64 `yaml:"watch_rate_limit"` // Zero disables rate limit WatchKeyBurstSize int `yaml:"watch_burst_size"` // Burst when doing rate-limit, defaults to 1 // Used in tests only. MaxCasRetries int `yaml:"-"` CasRetryDelay time.Duration `yaml:"-"` }
Config to create a ConsulClient