consul

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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) (*Client, error)

NewClient returns a new Client.

func NewInMemoryClient

func NewInMemoryClient(codec codec.Codec) *Client

NewInMemoryClient makes a new mock consul client.

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) Get

func (c *Client) Get(ctx context.Context, key string) (interface{}, error)

Get implements kv.Get.

func (*Client) WatchKey

func (c *Client) WatchKey(ctx context.Context, key string, f func(interface{}) bool)

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. Values in Consul are assumed to be JSON. This function blocks until the context is cancelled.

func (*Client) WatchPrefix

func (c *Client) WatchPrefix(ctx context.Context, prefix string, f func(string, interface{}) bool)

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
	ACLToken          string
	HTTPClientTimeout time.Duration
	ConsistentReads   bool
}

Config to create a ConsulClient

func (*Config) RegisterFlags

func (cfg *Config) RegisterFlags(f *flag.FlagSet, prefix string)

RegisterFlags adds the flags required to config this to the given FlagSet If prefix is not an empty string it should end with a period.

Jump to

Keyboard shortcuts

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