Documentation ¶
Index ¶
- type ConfigStore
- func (cs *ConfigStore) Arg() map[string]interface{}
- func (cs *ConfigStore) Defaults() map[string]interface{}
- func (cs *ConfigStore) Env() map[string]interface{}
- func (cs *ConfigStore) Load() error
- func (cs *ConfigStore) MapAll() map[string]interface{}
- func (cs *ConfigStore) MapLoaded() map[string]interface{}
- func (cs *ConfigStore) Save(in interface{}) (map[string]interface{}, error)
- func (cs *ConfigStore) SetArg(in map[string]interface{})
- func (cs *ConfigStore) SetEnv(prefixes []string, r *strings.Replacer)
- type LayeredStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConfigStore ¶
type ConfigStore struct { LayeredStore // contains filtered or unexported fields }
Store is a prioritized configuration registry. It maintains a set of configuration sources, fetches values to populate those, and provides them according to the source's priority.
The priority of the sources is the following:
- arguments
- env. variables
- config file
- defaults
For example, if values from the following sources were loaded:
Defaults : { "secret": "", "user": "default", "endpoint": "https://localhost" } Config : { "user": "root" "secret": "defaultsecret" } Env : { "secret": "somesecretkey" }
The resulting config will have the following values:
{ "secret": "somesecretkey", "user": "root", "endpoint": "https://localhost" }
func NewConfigStore ¶
func NewConfigStore(dsn string, defaults interface{}) (*ConfigStore, error)
New creates a config by file and struct with default value.
func (*ConfigStore) Arg ¶
func (cs *ConfigStore) Arg() map[string]interface{}
Arg returns the map of arguments.
func (*ConfigStore) Defaults ¶
func (cs *ConfigStore) Defaults() map[string]interface{}
Defaults returns the map cloned from struct.
func (*ConfigStore) Env ¶
func (cs *ConfigStore) Env() map[string]interface{}
Env returns the map of env. variable.
func (*ConfigStore) Load ¶
func (cs *ConfigStore) Load() error
func (*ConfigStore) MapAll ¶
func (cs *ConfigStore) MapAll() map[string]interface{}
MapAll returns the override map includes defaults, file, env. and arguments.
func (*ConfigStore) MapLoaded ¶
func (cs *ConfigStore) MapLoaded() map[string]interface{}
MapLoaded returns the map loaded from file.
func (*ConfigStore) Save ¶
func (cs *ConfigStore) Save(in interface{}) (map[string]interface{}, error)
Save saves the new configure struct.
Return the old configure map and error if occurred.
func (*ConfigStore) SetArg ¶
func (cs *ConfigStore) SetArg(in map[string]interface{})
SetArg sets the map of arguments. It scans and filters all env. variable by reference mas.
type LayeredStore ¶
type LayeredStore interface { // Existed returns true if the file was persisted. Existed() (bool, error) // Remove removes persisted configuration file. Remove() error // String describes the backing store for the config. String() string // Close cleans up resources associated with the store. Close() error // contains filtered or unexported methods }