diff --git a/Makefile b/Makefile index 0c0d3de95..79b7e04fc 100644 --- a/Makefile +++ b/Makefile @@ -92,17 +92,17 @@ btcd: build: @$(call print, "Building debug lnd and lncli.") - $(GOBUILD) -tags="$(DEV_TAGS)" -o lnd-debug $(LDFLAGS) $(PKG) + $(GOBUILD) -tags="$(DEV_TAGS)" -o lnd-debug $(LDFLAGS) $(PKG)/cmd/lnd $(GOBUILD) -tags="$(DEV_TAGS)" -o lncli-debug $(LDFLAGS) $(PKG)/cmd/lncli build-itest: @$(call print, "Building itest lnd and lncli.") - $(GOBUILD) -tags="$(ITEST_TAGS)" -o lnd-itest $(LDFLAGS) $(PKG) + $(GOBUILD) -tags="$(ITEST_TAGS)" -o lnd-itest $(LDFLAGS) $(PKG)/cmd/lnd $(GOBUILD) -tags="$(ITEST_TAGS)" -o lncli-itest $(LDFLAGS) $(PKG)/cmd/lncli install: @$(call print, "Installing lnd and lncli.") - $(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG) + $(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/lnd $(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/lncli scratch: build diff --git a/breacharbiter.go b/breacharbiter.go index be5e1b36d..33dd0fd8b 100644 --- a/breacharbiter.go +++ b/breacharbiter.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "bytes" diff --git a/breacharbiter_test.go b/breacharbiter_test.go index b3ae16930..8be6e992a 100644 --- a/breacharbiter_test.go +++ b/breacharbiter_test.go @@ -1,6 +1,6 @@ // +build !rpctest -package main +package lnd import ( "bytes" diff --git a/chainparams.go b/chainparams.go index 2d65d68ae..8313c6cf8 100644 --- a/chainparams.go +++ b/chainparams.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "github.com/btcsuite/btcd/chaincfg" diff --git a/chainregistry.go b/chainregistry.go index 71137e6a8..e50e9c69f 100644 --- a/chainregistry.go +++ b/chainregistry.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "encoding/hex" diff --git a/chancloser.go b/chancloser.go index 86361569c..be8395cec 100644 --- a/chancloser.go +++ b/chancloser.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "fmt" diff --git a/channel_notifier.go b/channel_notifier.go index c85f94e2e..36a2224a0 100644 --- a/channel_notifier.go +++ b/channel_notifier.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "fmt" diff --git a/chanrestore.go b/chanrestore.go index bb1ba6809..cf3bdf5b6 100644 --- a/chanrestore.go +++ b/chanrestore.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "fmt" diff --git a/cmd/lnd/main.go b/cmd/lnd/main.go new file mode 100644 index 000000000..177fb67d8 --- /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/config.go b/config.go index 0c0795850..63f475b0a 100644 --- a/config.go +++ b/config.go @@ -2,7 +2,7 @@ // Copyright (c) 2015-2016 The Decred developers // Copyright (C) 2015-2017 The Lightning Network Developers -package main +package lnd import ( "errors" diff --git a/doc.go b/doc.go index 06ab7d0f9..4e2eb5112 100644 --- a/doc.go +++ b/doc.go @@ -1 +1 @@ -package main +package lnd diff --git a/fundingmanager.go b/fundingmanager.go index 6a7e642c7..bc272312b 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "bytes" diff --git a/fundingmanager_test.go b/fundingmanager_test.go index 08e0b5571..75ba4eaa1 100644 --- a/fundingmanager_test.go +++ b/fundingmanager_test.go @@ -1,6 +1,6 @@ // +build !rpctest -package main +package lnd import ( "errors" diff --git a/lnd.go b/lnd.go index c3b40179f..41d6a49ef 100644 --- a/lnd.go +++ b/lnd.go @@ -2,7 +2,7 @@ // Copyright (c) 2015-2016 The Decred developers // Copyright (C) 2015-2017 The Lightning Network Developers -package main +package lnd import ( "bytes" @@ -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 { diff --git a/lnd_test.go b/lnd_test.go index 32462a5c8..51fe50edf 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -1,6 +1,6 @@ // +build rpctest -package main +package lnd import ( "bytes" diff --git a/log.go b/log.go index 37afa0bc7..8ddb7f6da 100644 --- a/log.go +++ b/log.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "fmt" diff --git a/mock.go b/mock.go index 6c1f3fb6a..10e077c54 100644 --- a/mock.go +++ b/mock.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "fmt" diff --git a/nursery_store.go b/nursery_store.go index eec8e74a9..d7f30d077 100644 --- a/nursery_store.go +++ b/nursery_store.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "bytes" diff --git a/nursery_store_test.go b/nursery_store_test.go index 0c2059580..af5e0a067 100644 --- a/nursery_store_test.go +++ b/nursery_store_test.go @@ -1,6 +1,6 @@ // +build !rpctest -package main +package lnd import ( "io/ioutil" diff --git a/peer.go b/peer.go index e227d141d..d7fcf2e11 100644 --- a/peer.go +++ b/peer.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "bytes" diff --git a/peer_test.go b/peer_test.go index 61251cd1e..9db7e7f36 100644 --- a/peer_test.go +++ b/peer_test.go @@ -1,6 +1,6 @@ // +build !rpctest -package main +package lnd import ( "testing" diff --git a/pilot.go b/pilot.go index 8a5cdd5ad..b8f3831ad 100644 --- a/pilot.go +++ b/pilot.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "errors" diff --git a/rpcserver.go b/rpcserver.go index 1c8e2fb7d..38280d3ee 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "bytes" diff --git a/server.go b/server.go index 50b8fd9ee..083ae07c4 100644 --- a/server.go +++ b/server.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "bytes" diff --git a/server_test.go b/server_test.go index 93ad3b683..ad2c04134 100644 --- a/server_test.go +++ b/server_test.go @@ -1,6 +1,6 @@ // +build !rpctest -package main +package lnd import "testing" diff --git a/subrpcserver_config.go b/subrpcserver_config.go index c697b03e5..4ba01552f 100644 --- a/subrpcserver_config.go +++ b/subrpcserver_config.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "fmt" diff --git a/test_utils.go b/test_utils.go index 9b30c300e..8d1fc3d1a 100644 --- a/test_utils.go +++ b/test_utils.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "bytes" diff --git a/utxonursery.go b/utxonursery.go index 36b978152..a95adcb9c 100644 --- a/utxonursery.go +++ b/utxonursery.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "bytes" diff --git a/utxonursery_test.go b/utxonursery_test.go index b300e4adc..05be1a0ae 100644 --- a/utxonursery_test.go +++ b/utxonursery_test.go @@ -1,6 +1,6 @@ // +build !rpctest -package main +package lnd import ( "bytes" diff --git a/witness_beacon.go b/witness_beacon.go index 1d368c581..82835226b 100644 --- a/witness_beacon.go +++ b/witness_beacon.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "sync"