From 7158103d4d0b50536b0db418974f5c2f043e92c2 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 30 Apr 2020 09:39:29 +0200 Subject: [PATCH] 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. --- cmd/lnd/main.go | 12 ++++++++++-- lnd.go | 10 ++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/cmd/lnd/main.go b/cmd/lnd/main.go index 3448b77a..42fab333 100644 --- a/cmd/lnd/main.go +++ b/cmd/lnd/main.go @@ -9,12 +9,20 @@ import ( ) 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 // 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 { } else { - fmt.Fprintln(os.Stderr, err) + _, _ = fmt.Fprintln(os.Stderr, err) } os.Exit(1) } diff --git a/lnd.go b/lnd.go index e796a762..9eb35bdd 100644 --- a/lnd.go +++ b/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 // created in the top-level scope of a main method aren't executed if os.Exit() // is called. -func Main(lisCfg ListenerCfg) error { +func Main(config *Config, lisCfg ListenerCfg) error { // Hook interceptor for os signals. signal.Intercept() - // Load the configuration, and parse any command line options. This - // function will also set up logging properly. - loadedConfig, err := LoadConfig() - if err != nil { - return err - } - cfg = loadedConfig + cfg = config defer func() { ltndLog.Info("Shutdown complete") err := RootLogWriter.Close()