Documentation ¶
Overview ¶
Package cconfig provides utilities to read app config files. See New and Loader for more documentation and example.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Loader ¶ added in v0.3.4
type Loader interface { // Load reads the config values defined under the given key (TOML table) and sets them into the dest struct. // For example: // # prod.toml // key1 = "val1" // // # config.go // type MyConfig struct { // Key1 string `toml:"key1"` // } // // func LoadMyConfig(loader cconfig.Loader) (MyConfig, error) { // var config MyConfig // // err := loader.Load("my_config", &config) // if err != nil { // return MyConfig{}, cerrors.New(err, "failed to load configs for my_config", nil) // } // // return config, nil // } Load(key string, dest interface{}) error }
Loader provides methods to load config files into structs.
func New ¶
New provides an implementation of Loader that reads a config file at the given file path. It supports extending the config file at the given path by using an 'extends' key. For example, the config file may be extended like so:
# base.toml key1 = "val1"
# prod.toml extends = "base.toml key2 = "val2"
If New is called with the path to prod.toml, it loads both key2 (from prod.toml) and key1 (from base.toml) since prod.toml extends base.toml.
The extends key can support multiple files like so: extends = ["base.toml", "secrets.toml"]
If a config key is present in multiple files, New returns an error. For example, if prod.toml sets a value for 'key1' that has already been set in base.toml, an error will be returned. To enable key overrides see NewWithKeyOverrides.
func NewWithKeyOverrides ¶ added in v0.3.4
NewWithKeyOverrides works exactly the same way as New except it supports key overrides. For example, this is a valid config: # base.toml key1 = "val1"
# prod.toml extends = "base.toml key1 = "val2"
If prod.toml is loaded, key1 will be set to "val2" since it has been overridden in prod.toml.
Directories ¶
Path | Synopsis |
---|---|
Package cconfigtest provides helper methods to test the cconfig package
|
Package cconfigtest provides helper methods to test the cconfig package |