Browse Source

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

master
Johan T. Halseth 5 years ago
parent
commit
9d1e1db42e
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
  1. 21
      cmd/lnd/main.go
  2. 25
      lnd.go

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

25
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 {

Loading…
Cancel
Save