lnd+config: move config parsing to cmd

Now that we have access to the configuration parsing outside of the
main package, we can move the actual parsing to the command line
package.
This commit is contained in:
Oliver Gugger 2020-04-30 09:39:29 +02:00
parent 3b2188d689
commit 7158103d4d
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
2 changed files with 12 additions and 10 deletions

@ -9,12 +9,20 @@ import (
) )
func main() { func main() {
// Load the configuration, and parse any command line options. This
// function will also set up logging properly.
loadedConfig, err := lnd.LoadConfig()
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
// Call the "real" main in a nested manner so the defers will properly // Call the "real" main in a nested manner so the defers will properly
// be executed in the case of a graceful shutdown. // be executed in the case of a graceful shutdown.
if err := lnd.Main(lnd.ListenerCfg{}); err != nil { if err := lnd.Main(loadedConfig, lnd.ListenerCfg{}); err != nil {
if e, ok := err.(*flags.Error); ok && e.Type == flags.ErrHelp { if e, ok := err.(*flags.Error); ok && e.Type == flags.ErrHelp {
} else { } else {
fmt.Fprintln(os.Stderr, err) _, _ = fmt.Fprintln(os.Stderr, err)
} }
os.Exit(1) os.Exit(1)
} }

10
lnd.go

@ -150,17 +150,11 @@ type rpcListeners func() ([]*ListenerWithSignal, func(), error)
// Main is the true entry point for lnd. This function is required since defers // Main is the true entry point for lnd. This function is required since defers
// created in the top-level scope of a main method aren't executed if os.Exit() // created in the top-level scope of a main method aren't executed if os.Exit()
// is called. // is called.
func Main(lisCfg ListenerCfg) error { func Main(config *Config, lisCfg ListenerCfg) error {
// Hook interceptor for os signals. // Hook interceptor for os signals.
signal.Intercept() signal.Intercept()
// Load the configuration, and parse any command line options. This cfg = config
// function will also set up logging properly.
loadedConfig, err := LoadConfig()
if err != nil {
return err
}
cfg = loadedConfig
defer func() { defer func() {
ltndLog.Info("Shutdown complete") ltndLog.Info("Shutdown complete")
err := RootLogWriter.Close() err := RootLogWriter.Close()