consul

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2018 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package consul contains an implementation of the `gokv.Store` interface for Consul.

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	Scheme:  "http",
	Address: "127.0.0.1:8500",
}

DefaultOptions is an Options object with default values. Scheme: "http", Address: "127.0.0.1:8500", Folder: none, MarshalFormat: JSON

Functions

This section is empty.

Types

type Client

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

Client is a gokv.Store implementation for Consul.

func NewClient

func NewClient(options Options) (Client, error)

NewClient creates a new Consul client.

func (Client) Delete

func (c Client) Delete(k string) error

Delete deletes the stored value for the given key. Deleting a non-existing key-value pair does NOT lead to an error. The key must not be "".

func (Client) Get

func (c Client) Get(k string, v interface{}) (bool, error)

Get retrieves the stored value for the given key. You need to pass a pointer to the value, so in case of a struct the automatic unmarshalling can populate the fields of the object that v points to with the values of the retrieved object's values. If no value is found it returns (false, nil). The key must not be "" and the pointer must not be nil.

func (Client) Set

func (c Client) Set(k string, v interface{}) error

Set stores the given value for the given key. Values are automatically marshalled to JSON or gob (depending on the configuration). The key must not be "" and the value must not be nil.

type MarshalFormat

type MarshalFormat int

MarshalFormat is an enum for the available (un-)marshal formats of this gokv.Store implementation.

const (
	// JSON is the MarshalFormat for (un-)marshalling to/from JSON
	JSON MarshalFormat = iota
	// Gob is the MarshalFormat for (un-)marshalling to/from gob
	Gob
)

type Options

type Options struct {
	// URI scheme for the Consul server.
	// Optional ("http" by default).
	Scheme string
	// Address of the Consul server, including port number.
	// Optional ("127.0.0.1:8500" by default).
	Address string
	// Directory under which to store the key-value pairs.
	// The Consul UI calls this "folder".
	// Optional (none by default).
	Folder string
	// (Un-)marshal format.
	// Optional (JSON by default).
	MarshalFormat MarshalFormat
}

Options are the options for the Consul client.

Jump to

Keyboard shortcuts

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