From d4d10b5c71780404c38ce3cc28f43b72d580869e Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 30 Apr 2020 09:55:32 +0200 Subject: [PATCH] config: extract default config into function To make it easy to extract the configuration parsing out of the main package, the default config is exported as its own function. --- config.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/config.go b/config.go index 1acc98402..46e06f6c2 100644 --- a/config.go +++ b/config.go @@ -289,16 +289,9 @@ type Config struct { AllowCircularRoute bool `long:"allow-circular-route" description:"If true, our node will allow htlc forwards that arrive and depart on the same channel."` } -// LoadConfig initializes and parses the config using a config file and command -// line options. -// -// The configuration proceeds as follows: -// 1) Start with a default config with sane settings -// 2) Pre-parse the command line to check for an alternative config file -// 3) Load configuration file overwriting defaults with any specified options -// 4) Parse CLI options and overwrite/add any specified options -func LoadConfig() (*Config, error) { - defaultCfg := Config{ +// DefaultConfig returns all default values for the Config struct. +func DefaultConfig() Config { + return Config{ LndDir: defaultLndDir, ConfigFile: defaultConfigFile, DataDir: defaultDataDir, @@ -397,10 +390,20 @@ func LoadConfig() (*Config, error) { MaxOutgoingCltvExpiry: htlcswitch.DefaultMaxOutgoingCltvExpiry, MaxChannelFeeAllocation: htlcswitch.DefaultMaxLinkFeeAllocation, } +} +// LoadConfig initializes and parses the config using a config file and command +// line options. +// +// The configuration proceeds as follows: +// 1) Start with a default config with sane settings +// 2) Pre-parse the command line to check for an alternative config file +// 3) Load configuration file overwriting defaults with any specified options +// 4) Parse CLI options and overwrite/add any specified options +func LoadConfig() (*Config, error) { // Pre-parse the command line options to pick up an alternative config // file. - preCfg := defaultCfg + preCfg := DefaultConfig() if _, err := flags.Parse(&preCfg); err != nil { return nil, err }