From ef0f771f61490f98efe2b02ec7999027936ab4bc Mon Sep 17 00:00:00 2001 From: "yanwei.han" Date: Thu, 16 Apr 2020 08:34:38 +0800 Subject: [PATCH] fix backend default config --- server/config/config_okchain.go | 18 +++++++++++++----- server/util.go | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/server/config/config_okchain.go b/server/config/config_okchain.go index 4ce0a91da2fd..57d834ebd88d 100644 --- a/server/config/config_okchain.go +++ b/server/config/config_okchain.go @@ -2,6 +2,7 @@ package config import ( "os" + "path/filepath" ) const ( @@ -9,10 +10,17 @@ const ( BackendOrmEngineTypeMysql = "mysql" ) -var ( - DefaultBackendNodeHome = os.ExpandEnv("$HOME/.okchaind") - DefaultBackendNodeDataHome = DefaultBackendNodeHome + "/data" -) +var defaultNodeHome = os.ExpandEnv("$HOME/.okchaind") + +// SetNodeHome sets the root directory for all data. +func SetNodeHome(home string) { + defaultNodeHome = home +} + +// GetNodeHome returns the root directory for all data. +func GetNodeHome() string { + return defaultNodeHome +} type BackendConfig struct { EnableBackend bool `json:"enable_backend" mapstructure:"enable_backend"` @@ -52,7 +60,7 @@ func DefaultBackendConfig() *BackendConfig { c.CleanUpsKeptDays["kline_m5"] = 120 c.OrmEngine.EngineType = BackendOrmEngineTypeSqlite - c.OrmEngine.ConnectStr = DefaultBackendNodeDataHome + string(os.PathSeparator) + c.OrmEngine.EngineType + string(os.PathSeparator) + "backend.sqlite3" + c.OrmEngine.ConnectStr = filepath.Join(GetNodeHome(), "data", c.OrmEngine.EngineType, "backend.sqlite3") return &c } diff --git a/server/util.go b/server/util.go index a9f1be7628db..cd1a0e39d476 100644 --- a/server/util.go +++ b/server/util.go @@ -114,6 +114,7 @@ func interceptLoadConfig() (conf *cfg.Config, err error) { } } + config.SetNodeHome(rootDir) appConfigFilePath := filepath.Join(rootDir, "config/okchaind.toml") if _, err := os.Stat(appConfigFilePath); os.IsNotExist(err) { appConf, _ := config.ParseConfig()