Merge pull request #272 from carlaKC/config-fixdefaultconfigpath

loopd: add network to default config file path
increase-sweep-conf-default
Carla Kirk-Cohen 4 years ago committed by GitHub
commit 175941e46e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -13,11 +13,14 @@ import (
var (
loopDirBase = btcutil.AppDataDir("loop", false)
defaultNetwork = "mainnet"
defaultLogLevel = "info"
defaultLogDirname = "logs"
defaultLogFilename = "loopd.log"
defaultLogDir = filepath.Join(loopDirBase, defaultLogDirname)
defaultConfigFile = filepath.Join(loopDirBase, defaultConfigFilename)
defaultConfigFile = filepath.Join(
loopDirBase, defaultNetwork, defaultConfigFilename,
)
defaultMaxLogFiles = 3
defaultMaxLogFileSize = 10
@ -75,7 +78,7 @@ const (
// DefaultConfig returns all default values for the Config struct.
func DefaultConfig() Config {
return Config{
Network: "mainnet",
Network: defaultNetwork,
RPCListen: "localhost:11010",
RESTListen: "localhost:8081",
Server: &loopServerConfig{

@ -137,17 +137,7 @@ func Run(rpcCfg RPCConfig) error {
// Parse ini file.
loopDir := lncfg.CleanAndExpandPath(config.LoopDir)
configFile := lncfg.CleanAndExpandPath(config.ConfigFile)
// If our loop directory is set and the config file parameter is not
// set, we assume that they want to point to a config file in their
// loop dir. However, if the config file has a non-default value, then
// we leave the config parameter as its custom value.
if loopDir != loopDirBase && configFile == defaultConfigFile {
configFile = filepath.Join(
loopDir, defaultConfigFilename,
)
}
configFile := getConfigPath(config, loopDir)
if err := flags.IniParse(configFile, &config); err != nil {
// If it's a parsing related error, then we'll return
@ -237,3 +227,25 @@ func Run(rpcCfg RPCConfig) error {
return fmt.Errorf("unimplemented command %v", parser.Active.Name)
}
// getConfigPath gets our config path based on the values that are set in our
// config.
func getConfigPath(cfg Config, loopDir string) string {
// If the config file path provided by the user is set, then we just
// use this value.
if cfg.ConfigFile != defaultConfigFile {
return lncfg.CleanAndExpandPath(cfg.ConfigFile)
}
// If the user has set a loop directory that is different to the default
// we will use this loop directory as the location of our config file.
// We do not namespace by network, because this is a custom loop dir.
if loopDir != loopDirBase {
return filepath.Join(loopDir, defaultConfigFilename)
}
// Otherwise, we are using our default loop directory, and the user did
// not set a config file path. We use our default loop dir, namespaced
// by network.
return filepath.Join(loopDir, cfg.Network, defaultConfigFilename)
}

Loading…
Cancel
Save