micro/config
magodo 7acd249147 config consul source supports slash as prefix
`config.NewConfig()` with consul source will both read from consul
and watch consul for changes. Hence, the `prefix` is used in these
2 cases:

- read case: it is used to strip path based on the `KVPair` returned
from consul `kv.List()` method
- watch case: it is used as the `key` of watch query (`keyprefix` type)

So for *watch case*, the `key` is leagal to be `/` for watching change
on root. While for *read case*, because `KVPair.Key` is always stripped
off the leading slash, so if user specified some `prefix` with leading
slash, we should strip it also.

An extream case would be: user want's to read & watch node in root dir.
One would specify `prefix` as `/`, and it should work then.
2019-06-21 16:35:48 +08:00
..
encoder add config 2019-05-30 23:11:13 +01:00
loader add config 2019-05-30 23:11:13 +01:00
options move options under config 2019-06-12 12:45:42 +01:00
reader add config 2019-05-30 23:11:13 +01:00
source config consul source supports slash as prefix 2019-06-21 16:35:48 +08:00
config.go add config 2019-05-30 23:11:13 +01:00
default_test.go add config 2019-05-30 23:11:13 +01:00
default.go add config 2019-05-30 23:11:13 +01:00
issue18_test.go add config 2019-05-30 23:11:13 +01:00
options.go add config 2019-05-30 23:11:13 +01:00
README.md add config 2019-05-30 23:11:13 +01:00
value.go add config 2019-05-30 23:11:13 +01:00

Config GoDoc

Go Config is a pluggable dynamic config library.

Most config in applications are statically configured or include complex logic to load from multiple sources. Go Config makes this easy, pluggable and mergeable. You'll never have to deal with config in the same way again.

Features

  • Dynamic Loading - Load configuration from multiple source as and when needed. Go Config manages watching config sources in the background and automatically merges and updates an in memory view.

  • Pluggable Sources - Choose from any number of sources to load and merge config. The backend source is abstracted away into a standard format consumed internally and decoded via encoders. Sources can be env vars, flags, file, etcd, k8s configmap, etc.

  • Mergeable Config - If you specify multiple sources of config, regardless of format, they will be merged and presented in a single view. This massively simplifies priority order loading and changes based on environment.

  • Observe Changes - Optionally watch the config for changes to specific values. Hot reload your app using Go Config's watcher. You don't have to handle ad-hoc hup reloading or whatever else, just keep reading the config and watch for changes if you need to be notified.

  • Sane Defaults - In case config loads badly or is completely wiped away for some unknown reason, you can specify fallback values when accessing any config values directly. This ensures you'll always be reading some sane default in the event of a problem.

Getting Started

For detailed information or architecture, installation and general usage see the docs