etcd

package
v2.9.9 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2022 License: Apache-2.0 Imports: 11 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

View Source
var (
	DefaultPrefix = "/micro/config/"
)

Functions

func Auth

func Auth(username, password string) source.Option

Auth allows you to specify username/password

func NewSource

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

func StripPrefix

func StripPrefix(strip bool) source.Option

StripPrefix indicates whether to remove the prefix from config entries, or leave it in place.

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 WithPrefix

func WithPrefix(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