lnd: move main method to cmd/lnd/main.go

This commit is contained in:
Johan T. Halseth 2019-01-24 14:28:25 +01:00
parent 6c60caa852
commit 9d1e1db42e
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
2 changed files with 28 additions and 18 deletions

21
cmd/lnd/main.go Normal file

@ -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)
}
}

25
lnd.go

@ -18,7 +18,6 @@ import (
"math/big" "math/big"
"net" "net"
"net/http" "net/http"
_ "net/http/pprof"
"os" "os"
"path/filepath" "path/filepath"
"runtime/pprof" "runtime/pprof"
@ -26,6 +25,9 @@ import (
"sync" "sync"
"time" "time"
// Blank import to set up profiling HTTP handlers.
_ "net/http/pprof"
"gopkg.in/macaroon-bakery.v2/bakery" "gopkg.in/macaroon-bakery.v2/bakery"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -36,7 +38,6 @@ import (
"github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcwallet/wallet" "github.com/btcsuite/btcwallet/wallet"
proxy "github.com/grpc-ecosystem/grpc-gateway/runtime" proxy "github.com/grpc-ecosystem/grpc-gateway/runtime"
flags "github.com/jessevdk/go-flags"
"github.com/lightninglabs/neutrino" "github.com/lightninglabs/neutrino"
"github.com/lightningnetwork/lnd/autopilot" "github.com/lightningnetwork/lnd/autopilot"
@ -89,10 +90,10 @@ var (
} }
) )
// lndMain is the true entry point for lnd. This function is required since // Main is the true entry point for lnd. This function is required since defers
// defers created in the top-level scope of a main method aren't executed if // created in the top-level scope of a main method aren't executed if os.Exit()
// os.Exit() is called. // is called.
func lndMain() error { func Main() error {
// Load the configuration, and parse any command line options. This // Load the configuration, and parse any command line options. This
// function will also set up logging properly. // function will also set up logging properly.
loadedConfig, err := loadConfig() loadedConfig, err := loadConfig()
@ -468,18 +469,6 @@ func getTLSConfig(cfg *config) (*tls.Config, *credentials.TransportCredentials,
return tlsCfg, &restCreds, restProxyDest, nil 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. // fileExists reports whether the named file or directory exists.
// This function is taken from https://github.com/btcsuite/btcd // This function is taken from https://github.com/btcsuite/btcd
func fileExists(name string) bool { func fileExists(name string) bool {