consulkv

package module
v0.0.0-...-044c7ba Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2015 License: MIT Imports: 10 Imported by: 22

README

consul-kv

DEPRECATED Please use consul api package instead. Godocs for that package are here.

This package provides the consulkv package which is a Key/Value client for Consul. It supports all the commands as of Consul 0.1, and has a very simple API.

Documentation

The full documentation is available on Godoc

Usage

Below is an example of using the Consul KV client:

client, _ := consulkv.NewClient(consulkv.DefaultConfig())

key := "foo"
value := []byte("test")
client.Put(key, value, 42)

meta, pair, err := client.Get(key)
fmt.Printf("Got %s (%d): %s", pair.Key, pair.Flags, pair.Value)

Development

To run the tests, first run a consul server with API port 8500:

consul agent -data-dir /tmp/consul -server -bootstrap

The run tests:

go test

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client provides a client to Consul for K/V data

func NewClient

func NewClient(config *Config) (*Client, error)

NewClient returns a new

func (*Client) CAS

func (c *Client) CAS(key string, value []byte, flags, index uint64) (bool, error)

CAS is used for a Check-And-Set operation

func (*Client) Delete

func (c *Client) Delete(key string) error

Delete is used to delete a single key

func (*Client) DeleteTree

func (c *Client) DeleteTree(prefix string) error

DeleteTree is used to delete all keys with a prefix

func (*Client) Get

func (c *Client) Get(key string) (*KVMeta, *KVPair, error)

Get is used to lookup a single key

func (*Client) List

func (c *Client) List(prefix string) (*KVMeta, KVPairs, error)

List is used to lookup all keys with a prefix

func (*Client) Put

func (c *Client) Put(key string, value []byte, flags uint64) error

Put is used to set a value for a given key

func (*Client) WatchGet

func (c *Client) WatchGet(key string, modifyIndex uint64) (*KVMeta, *KVPair, error)

WatchGet is used to block and wait for a change on a key

func (*Client) WatchList

func (c *Client) WatchList(prefix string, modifyIndex uint64) (*KVMeta, KVPairs, error)

WatchList is used to block and wait for a change on a prefix

type Config

type Config struct {
	// Address is the address of the Consul server
	Address string

	// Datacenter to use. If not provided, the default agent datacenter is used.
	Datacenter string

	// HTTPClient is the client to use. Default will be
	// used if not provided.
	HTTPClient *http.Client

	// WaitTime limits how long a Watch will block. If not provided,
	// the agent default values will be used.
	WaitTime time.Duration
}

Config is used to configure the creation of a client

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default configuration for the client

type KVMeta

type KVMeta struct {
	ModifyIndex uint64
}

KVMeta provides meta data about a query

type KVPair

type KVPair struct {
	Key         string
	CreateIndex uint64
	ModifyIndex uint64
	Flags       uint64
	Value       []byte
}

KVPair is used to represent a single K/V entry

type KVPairs

type KVPairs []*KVPair

KVPairs is a list of KVPair objects

Jump to

Keyboard shortcuts

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