From 9d1e1db42ef96a85ae91696f3297043b9ac4634b Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 24 Jan 2019 14:28:25 +0100 Subject: [PATCH] lnd: move main method to cmd/lnd/main.go --- cmd/lnd/main.go | 21 +++++++++++++++++++++ lnd.go | 25 +++++++------------------ 2 files changed, 28 insertions(+), 18 deletions(-) create mode 100644 cmd/lnd/main.go diff --git a/cmd/lnd/main.go b/cmd/lnd/main.go new file mode 100644 index 00000000..177fb67d --- /dev/null +++ b/cmd/lnd/main.go @@ -0,0 +1,21 @@ +package main + +import ( + "fmt" + "os" + + flags "github.com/jessevdk/go-flags" + "github.com/lightningnetwork/lnd" +) + +func main() { + // 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(); err != nil { + if e, ok := err.(*flags.Error); ok && e.Type == flags.ErrHelp { + } else { + fmt.Fprintln(os.Stderr, err) + } + os.Exit(1) + } +} diff --git a/lnd.go b/lnd.go index c3b40179..318ac3ef 100644 --- a/lnd.go +++ b/lnd.go @@ -18,7 +18,6 @@ import ( "math/big" "net" "net/http" - _ "net/http/pprof" "os" "path/filepath" "runtime/pprof" @@ -26,6 +25,9 @@ import ( "sync" "time" + // Blank import to set up profiling HTTP handlers. + _ "net/http/pprof" + "gopkg.in/macaroon-bakery.v2/bakery" "golang.org/x/net/context" @@ -36,7 +38,6 @@ import ( "github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcwallet/wallet" proxy "github.com/grpc-ecosystem/grpc-gateway/runtime" - flags "github.com/jessevdk/go-flags" "github.com/lightninglabs/neutrino" "github.com/lightningnetwork/lnd/autopilot" @@ -89,10 +90,10 @@ var ( } ) -// lndMain 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 lndMain() 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() error { // Load the configuration, and parse any command line options. This // function will also set up logging properly. loadedConfig, err := loadConfig() @@ -468,18 +469,6 @@ func getTLSConfig(cfg *config) (*tls.Config, *credentials.TransportCredentials, return tlsCfg, &restCreds, restProxyDest, nil } -func main() { - // Call the "real" main in a nested manner so the defers will properly - // be executed in the case of a graceful shutdown. - if err := lndMain(); err != nil { - if e, ok := err.(*flags.Error); ok && e.Type == flags.ErrHelp { - } else { - fmt.Fprintln(os.Stderr, err) - } - os.Exit(1) - } -} - // fileExists reports whether the named file or directory exists. // This function is taken from https://github.com/btcsuite/btcd func fileExists(name string) bool {