diff --git a/README.md b/README.md index bfa2a41..cc4cd72 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,9 @@ go install github.com/edouardparis/lntop@latest ## Config -First time `lntop` is used a config file `.lntop/config.toml` is created -in the user home directory. +First time `lntop` is started, a config file `.lntop/config.toml` is created in the user's home directory. Change `address`, `cert` path and `macaroon` path according to your setup. -Change macaroon path according to your network. +The following environment variables, if present, will be used in the initial config file instead of the defaults, so you won't have to have `lntop` fail on the first start and then manually edit the config file: `LND_ADDRESS`, `CERT_PATH`, `MACAROON_PATH`. ```toml [logger] diff --git a/config/default.go b/config/default.go index 5284a5c..9b48361 100644 --- a/config/default.go +++ b/config/default.go @@ -2,6 +2,7 @@ package config import ( "fmt" + "os" "os/user" "path" ) @@ -94,6 +95,18 @@ columns = [ func NewDefault() *Config { usr, _ := user.Current() + lndAddress, present := os.LookupEnv("LND_ADDRESS") + if !present { + lndAddress = "//127.0.0.1:10009" + } + certPath, present := os.LookupEnv("CERT_PATH") + if !present { + certPath = path.Join(usr.HomeDir, ".lnd/tls.cert") + } + macaroonPath, present := os.LookupEnv("MACAROON_PATH") + if !present { + macaroonPath = path.Join(usr.HomeDir, ".lnd/data/chain/bitcoin/mainnet/readonly.macaroon") + } return &Config{ Logger: Logger{ Type: "production", @@ -102,9 +115,9 @@ func NewDefault() *Config { Network: Network{ Name: "lnd", Type: "lnd", - Address: "//127.0.0.1:10009", - Cert: path.Join(usr.HomeDir, ".lnd/tls.cert"), - Macaroon: path.Join(usr.HomeDir, ".lnd/data/chain/bitcoin/mainnet/readonly.macaroon"), + Address: lndAddress, + Cert: certPath, + Macaroon: macaroonPath, MacaroonTimeOut: 60, MaxMsgRecvSize: 52428800, ConnTimeout: 1000000,