Create LoadJSONFileAndEnv config method for convenience
License: MIT Signed-off-by: Robert Ignat <robert.ignat91@gmail.com>
This commit is contained in:
parent
168cf76224
commit
523e109ef1
|
@ -69,7 +69,7 @@ func daemon(c *cli.Context) error {
|
|||
// always wait for configuration to be saved
|
||||
defer cfgMgr.Shutdown()
|
||||
|
||||
err = cfgMgr.LoadJSONFromFile(configPath)
|
||||
err = cfgMgr.LoadJSONFileAndEnv(configPath)
|
||||
checkErr("loading configuration", err)
|
||||
|
||||
if c.Bool("stats") {
|
||||
|
|
|
@ -442,7 +442,7 @@ the mth data folder (m currently defaults to 5)
|
|||
}
|
||||
|
||||
cfgMgr, cfgs := makeConfigs()
|
||||
err = cfgMgr.LoadJSONFromFile(configPath)
|
||||
err = cfgMgr.LoadJSONFileAndEnv(configPath)
|
||||
checkErr("reading configuration", err)
|
||||
|
||||
err = cleanupState(cfgs.consensusCfg)
|
||||
|
|
|
@ -34,7 +34,7 @@ func upgrade(ctx context.Context) error {
|
|||
|
||||
cfgMgr, cfgs := makeConfigs()
|
||||
|
||||
err = cfgMgr.LoadJSONFromFile(configPath)
|
||||
err = cfgMgr.LoadJSONFileAndEnv(configPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ func restoreStateFromDisk(ctx context.Context) (*mapstate.MapState, bool, error)
|
|||
|
||||
cfgMgr, cfgs := makeConfigs()
|
||||
|
||||
err := cfgMgr.LoadJSONFromFile(configPath)
|
||||
err := cfgMgr.LoadJSONFileAndEnv(configPath)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ func stateImport(ctx context.Context, r io.Reader) error {
|
|||
|
||||
cfgMgr, cfgs := makeConfigs()
|
||||
|
||||
err := cfgMgr.LoadJSONFromFile(configPath)
|
||||
err := cfgMgr.LoadJSONFileAndEnv(configPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -322,6 +322,17 @@ func (cfg *Manager) LoadJSONFromFile(path string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// LoadJSONFileAndEnv calls LoadJSONFromFile followed by ApplyEnvVars,
|
||||
// reading and parsing a Configuration file and then overriding fields
|
||||
// with any values found in environment variables.
|
||||
func (cfg *Manager) LoadJSONFileAndEnv(path string) error {
|
||||
if err := cfg.LoadJSONFromFile(path); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cfg.ApplyEnvVars()
|
||||
}
|
||||
|
||||
// LoadJSON parses configurations for all registered components,
|
||||
// In order to work, component configurations must have been registered
|
||||
// beforehand with RegisterComponent.
|
||||
|
|
Loading…
Reference in New Issue
Block a user