2
0
mirror of https://github.com/edouardparis/lntop synced 2024-11-04 06:00:14 +00:00

Merge pull request #48 from ibz/envconfig

Ability to read initial config from environment.
This commit is contained in:
Edouard 2021-12-03 18:11:32 +01:00 committed by GitHub
commit a05908af1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 6 deletions

View File

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

View File

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