Skip to content
This repository has been archived by the owner on Dec 21, 2022. It is now read-only.

fix backend default config #2

Merged
merged 1 commit into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions server/config/config_okchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@ package config

import (
"os"
"path/filepath"
)

const (
BackendOrmEngineTypeSqlite = "sqlite3"
BackendOrmEngineTypeMysql = "mysql"
)

var (
DefaultBackendNodeHome = os.ExpandEnv("$HOME/.okchaind")
DefaultBackendNodeDataHome = DefaultBackendNodeHome + "/data"
)
var defaultNodeHome = os.ExpandEnv("$HOME/.okchaind")
xiangjianmeng marked this conversation as resolved.
Show resolved Hide resolved

// 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"`
Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down