Documentation
¶
Overview ¶
Package config provides a layered configuration abstraction inspired by go-micro: Source (data origin) -> Loader (decode + merge) -> Reader (random access) -> Value (typed access). Backends such as local files and the Polaris config center implement Source.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterSource ¶
func RegisterSource(name string, f SourceFactory)
RegisterSource registers a SourceFactory under name. Source packages call this from init().
func RegisteredSource ¶
RegisteredSource reports whether a source is registered under name. It is used by validation to avoid hardcoding source whitelists.
Types ¶
type Config ¶
type Config interface {
// Load loads from the configured sources.
Load() error
// Watch invokes fn whenever the configuration changes.
Watch(fn func(Config)) error
// Close releases resources.
Close() error
Value(path string) Value
Scan(v interface{}) error
Reader() Reader
}
Config is the top-level entry point. An App typically owns one Config.
type KeyValue ¶
type KeyValue struct {
Key string
Value []byte
Format string // "json", "yaml", "toml"; empty means auto-detect.
}
KeyValue is a raw configuration key/value returned by a Source.
type Reader ¶
type Reader interface {
// Merge decodes and merges raw key/values.
Merge(kvs ...*KeyValue) error
// Value returns the value at a dot-separated path, e.g. "a.b.c".
Value(path string) Value
// Source returns the merged raw bytes.
Source() ([]byte, error)
}
Reader provides random access to merged configuration.
type Source ¶
type Source interface {
// Load returns the current raw key/values.
Load() ([]*KeyValue, error)
// Watch returns a Watcher that emits raw changes.
Watch() (Watcher, error)
}
Source reads raw configuration from a backend (file, remote config center, environment, ...).
type SourceFactory ¶
SourceFactory constructs a Source from a backend-specific options value. Concrete sources register their factory in init() and type-assert the options to their own typed Options struct, mirroring registry.RegisterRegistrar.
Directories
¶
| Path | Synopsis |
|---|---|
|
source
|
|
|
file
Package file implements a local-file config.Source with polling-based hot-reload.
|
Package file implements a local-file config.Source with polling-based hot-reload. |
|
polaris
Package polaris implements a config.Source backed by the Polaris config center (github.com/polarismesh/polaris-go).
|
Package polaris implements a config.Source backed by the Polaris config center (github.com/polarismesh/polaris-go). |