diff --git a/config/config.go b/config/config.go index 7e45a26fb85..b41a25bc5c3 100644 --- a/config/config.go +++ b/config/config.go @@ -1850,9 +1850,14 @@ func (c *Config) UpdateConfig(configPath string, newCfg *Config, dryrun bool) er return c.LoadConfig(configPath, dryrun) } -// GetConfig returns a pointer to a configuration object +// GetConfig returns the global shared config instance func GetConfig() *Config { - return &Cfg + return &cfg +} + +// SetConfig sets the global shared config instance +func SetConfig(c *Config) { + cfg = *c } // RemoveExchange removes an exchange config diff --git a/config/config_types.go b/config/config_types.go index a9411b8048c..ab662f14ddb 100644 --- a/config/config_types.go +++ b/config/config_types.go @@ -76,12 +76,16 @@ const ( DefaultUnsetAccountPlan = "accountPlan" ) +// Public errors exported by this package var ( - Cfg Config - m sync.Mutex ErrExchangeNotFound = errors.New("exchange not found") ) +var ( + cfg Config + m sync.Mutex +) + // Config is the overarching object that holds all the information for // prestart management of Portfolio, Communications, Webserver and Enabled // Exchanges diff --git a/engine/engine.go b/engine/engine.go index d6711406b36..aeb2e037e17 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -64,7 +64,7 @@ func New() (*Engine, error) { newEngineMutex.Lock() defer newEngineMutex.Unlock() var b Engine - b.Config = &config.Cfg + b.Config = config.GetConfig() err := b.Config.LoadConfig("", false) if err != nil { diff --git a/main.go b/main.go index 8d71e29b380..d84ac9cf7cd 100644 --- a/main.go +++ b/main.go @@ -135,7 +135,7 @@ func main() { if engine.Bot == nil || err != nil { log.Fatalf("Unable to initialise bot engine. Error: %s\n", err) } - config.Cfg = *engine.Bot.Config + config.SetConfig(engine.Bot.Config) gctscript.Setup()