Merge pull request #1926 from halseth/lnd-package

Move daemon from main to lnd package
This commit is contained in:
Olaoluwa Osuntokun 2019-04-25 17:52:19 -07:00 committed by GitHub
commit b44556fa8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 59 additions and 49 deletions

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

@ -1,4 +1,4 @@
package main
package lnd
import (
"bytes"

@ -1,6 +1,6 @@
// +build !rpctest
package main
package lnd
import (
"bytes"

@ -1,4 +1,4 @@
package main
package lnd
import (
"github.com/btcsuite/btcd/chaincfg"

@ -1,4 +1,4 @@
package main
package lnd
import (
"encoding/hex"

@ -1,4 +1,4 @@
package main
package lnd
import (
"fmt"

@ -1,4 +1,4 @@
package main
package lnd
import (
"fmt"

@ -1,4 +1,4 @@
package main
package lnd
import (
"fmt"

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

@ -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"

2
doc.go

@ -1 +1 @@
package main
package lnd

@ -1,4 +1,4 @@
package main
package lnd
import (
"bytes"

@ -1,6 +1,6 @@
// +build !rpctest
package main
package lnd
import (
"errors"

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

@ -1,6 +1,6 @@
// +build rpctest
package main
package lnd
import (
"bytes"

2
log.go

@ -1,4 +1,4 @@
package main
package lnd
import (
"fmt"

@ -1,4 +1,4 @@
package main
package lnd
import (
"fmt"

@ -1,4 +1,4 @@
package main
package lnd
import (
"bytes"

@ -1,6 +1,6 @@
// +build !rpctest
package main
package lnd
import (
"io/ioutil"

@ -1,4 +1,4 @@
package main
package lnd
import (
"bytes"

@ -1,6 +1,6 @@
// +build !rpctest
package main
package lnd
import (
"testing"

@ -1,4 +1,4 @@
package main
package lnd
import (
"errors"

@ -1,4 +1,4 @@
package main
package lnd
import (
"bytes"

@ -1,4 +1,4 @@
package main
package lnd
import (
"bytes"

@ -1,6 +1,6 @@
// +build !rpctest
package main
package lnd
import "testing"

@ -1,4 +1,4 @@
package main
package lnd
import (
"fmt"

@ -1,4 +1,4 @@
package main
package lnd
import (
"bytes"

@ -1,4 +1,4 @@
package main
package lnd
import (
"bytes"

@ -1,6 +1,6 @@
// +build !rpctest
package main
package lnd
import (
"bytes"

@ -1,4 +1,4 @@
package main
package lnd
import (
"sync"