etcd

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package etcd provides a config getter for etcd v3 key/value stores.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Getter

type Getter struct {
	config.GetterAsOption
	// contains filtered or unexported fields
}

Getter represents a getter from an etcd v3 key/value store. It is assumed that the relevant configuration is located within a section of the etcd keyspace with a fixed key prefix, e.g. /my/app/config/.

func New

func New(ctx context.Context, prefix string, options ...Option) (*Getter, error)

New creates a new etcd getter for the given prefix, and loads the configuration. The prefix defines the root of the configuration in the etcd space. The ctx covers the initial loading of configuration.

func (*Getter) Close

func (g *Getter) Close() error

Close closes the getters connection to the server. This automatically closes any active watchers. The current configuration snapshot can still be accessed via Get.

func (*Getter) Get

func (g *Getter) Get(key string) (interface{}, bool)

Get implements the Getter API.

func (*Getter) NewWatcher

func (g *Getter) NewWatcher(done <-chan struct{}) config.GetterWatcher

NewWatcher creates a watcher goroutine if watcher was enabled during construction.

type Option

type Option func(*Getter)

Option is a function which modifies an Etcd getter at construction time.

func WithClient

func WithClient(client *clientv3.Client) Option

WithClient sets the etcd client. The default is constructed from the clientConfig.

func WithClientConfig

func WithClientConfig(cfg clientv3.Config) Option

WithClientConfig sets the configuration of the etcd client. The default is an empty config with one endpoint - "localhost:2379".

func WithEndpoint

func WithEndpoint(endpoints ...string) Option

WithEndpoint sets the endpoint URL of the client port of the etcd server. The default endpoint is "localhost:2379".

func WithKeyReplacer

func WithKeyReplacer(keyReplacer keys.Replacer) Option

WithKeyReplacer sets the replacer used to map from etcd space to config space. The default replaces '/' in the etcd space with '.' in the config space.

func WithListSplitter

func WithListSplitter(splitter list.Splitter) Option

WithListSplitter splits slice fields stored as strings in the etcd space. The default splitter separates on ",".

func WithWatcher

func WithWatcher() Option

WithWatcher is an Option that enables watching of the etcd. This is an option to ensure it can only set at construction time, so the watcher is a singleton.

Jump to

Keyboard shortcuts

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