etcd

package
v1.0.18 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: BSD-3-Clause Imports: 10 Imported by: 0

README

Etcd Source

The etcd source reads config from etcd key/values

This source supports etcd version 3 and beyond.

Etcd Format

The etcd source expects keys under the default prefix /micro/config (prefix can be changed)

Values are expected to be JSON

// set database
etcdctl put /micro/config/database '{"address": "10.0.0.1", "port": 3306}'
// set cache
etcdctl put /micro/config/cache '{"address": "10.0.0.2", "port": 6379}'

Keys are split on / so access becomes

conf.Get("micro", "config", "database")

New Source

Specify source with data

etcdSource := etcd.NewSource(
	// optionally specify etcd address; default to localhost:8500
	etcd.WithAddress("10.0.0.10:8500"),
	// optionally specify prefix; defaults to /micro/config
	etcd.WithPrefix("/my/prefix"),
	// optionally strip the provided prefix from the keys, defaults to false
	etcd.StripPrefix(true),
)

Load Source

Load the source into config

// Create new config
conf := config.NewConfig()

// Load file source
conf.Load(etcdSource)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicAuth added in v1.0.17

func BasicAuth(username, password string) source.Option

BasicAuth allows you to specify username/password

func NewSource

func NewSource(opts ...source.Option) source.Source

func TLSAuth added in v1.0.17

func TLSAuth(caFile, certFile, keyFile string) source.Option

TLSAuth allows you to specify cafile, certfile, keyfile

func WithAddress

func WithAddress(a ...string) source.Option

WithAddress sets the etcd address

func WithDialTimeout

func WithDialTimeout(timeout time.Duration) source.Option

WithDialTimeout set the time out for dialing to etcd

func WithPath

func WithPath(p string) source.Option

WithPrefix sets the key prefix to use

Types

This section is empty.

Jump to

Keyboard shortcuts

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