kletcd

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2019 License: MIT Imports: 10 Imported by: 0

README

Etcd Loader

Loads configs from Etcd into konfig.Store

Usage

Basic usage loading keys and using result as string with watcher

etcdLoader := kletcd.New(&kletc.Config{
	Client: etcdClient, // from go.etcd.io/etcd/clientv3 package
	Keys: []Key{
		{
			Key: "foo/bar",
		},
	},
	Watch: true,
})

Loading keys and JSON parser

etcdLoader := kletcd.New(&kletc.Config{
	Client: etcdClient, // from go.etcd.io/etcd/clientv3 package
	Keys: []Key{
		{
			Key: "foo/bar",
			Parser: kpjson.Parser,
		},
	},
	Watch: true,
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Name is the name of the loader
	Name string
	// StopOnFailure tells whether a failure to load configs should closed the config and all registered closers
	StopOnFailure bool
	// Client is the etcd client
	Client *clientv3.Client
	// Keys is the list of keys to fetch
	Keys []Key
	// Timeout is the timeout duration when fetching a key
	Timeout time.Duration
	// Prefix is a prefix to prepend keys when adding into the konfig.Store
	Prefix string
	// Replacer is a Replacer for the key before adding to the konfig.Store
	Replacer nstrings.Replacer
	// Watch tells whether there should be a watcher with the loader
	Watch bool
	// Rater is the rater to pass to the poll watcher
	Rater kwpoll.Rater
	// MaxRetry is the maximum number of times we can retry to load if it fails
	MaxRetry int
	// RetryDelay is the time between each retry when a load fails
	RetryDelay time.Duration
	// Debug sets debug mode on the etcdloader
	Debug bool
	// Contexter provides a context, default value is contexter wrapping context package. It is used mostly for testing.
	Contexter ncontext.Contexter
	// contains filtered or unexported fields
}

Config is the structure representing the config of a Loader

type Key

type Key struct {
	// Key is the etcd key
	Key string
	// Parser is the parser for the key
	// If nil, the value is casted to a string before adding to the config.Store
	Parser parser.Parser
}

Key is an Etcd Key to load

type Loader

type Loader struct {
	*kwpoll.PollWatcher
	// contains filtered or unexported fields
}

Loader is the structure of a loader

func New

func New(cfg *Config) *Loader

New returns a new loader with the given config

func (*Loader) Load

func (l *Loader) Load(s konfig.Values) error

Load loads the values from the keys defined by the config in the konfig.Store

func (*Loader) MaxRetry

func (l *Loader) MaxRetry() int

MaxRetry is the maximum number of time to retry when a load fails

func (*Loader) Name

func (l *Loader) Name() string

Name returns the name of the loader

func (*Loader) RetryDelay

func (l *Loader) RetryDelay() time.Duration

RetryDelay is the delay between each retry

func (*Loader) StopOnFailure

func (l *Loader) StopOnFailure() bool

StopOnFailure returns whether a load failure should stop the config and the registered closers

Jump to

Keyboard shortcuts

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