mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-20 06:42:00 +01:00
With this commit we extract the wallet creation/unlocking and initialization completely out of the main function. This will allow us to use custom implementations in the future.
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/jessevdk/go-flags"
|
|
"github.com/lightningnetwork/lnd"
|
|
"github.com/lightningnetwork/lnd/signal"
|
|
)
|
|
|
|
func main() {
|
|
// Hook interceptor for os signals.
|
|
shutdownInterceptor, err := signal.Intercept()
|
|
if err != nil {
|
|
_, _ = fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// Load the configuration, and parse any command line options. This
|
|
// function will also set up logging properly.
|
|
loadedConfig, err := lnd.LoadConfig(shutdownInterceptor)
|
|
if err != nil {
|
|
if e, ok := err.(*flags.Error); !ok || e.Type != flags.ErrHelp {
|
|
// Print error if not due to help request.
|
|
err = fmt.Errorf("failed to load config: %w", err)
|
|
_, _ = fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// Help was requested, exit normally.
|
|
os.Exit(0)
|
|
}
|
|
implCfg := loadedConfig.ImplementationConfig(shutdownInterceptor)
|
|
|
|
// 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(
|
|
loadedConfig, lnd.ListenerCfg{}, implCfg, shutdownInterceptor,
|
|
); err != nil {
|
|
_, _ = fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|