diff --git a/README.md b/README.md index 506efbb..30d82fa 100644 --- a/README.md +++ b/README.md @@ -39,24 +39,49 @@ LnMe can easily run next to LND on the same system. To connect to the lnd node the cert, macaroon and address of the lnd node has to be configured. LnMe uses the LND defaults. -* `address`: Host and port of the lnd gRPC service. default: localhost:10009 -* `cert`: Path to the lnd cert file. default: ~/.lnd/tls.cert -* `macaroon`: Path to the macaroon file. default: ~/.lnd/data/chain/bitcoin/mainnet/invoice.macaroon +* `lnd-address`: Host and port of the LND gRPC service. default: localhost:10009 +* `lnd-cert-path`: Path to the LND TLS cert file. default: ~/.lnd/tls.cert +* `lnd-macaroon-path`: Path to the LND macaroon file. default: ~/.lnd/data/chain/bitcoin/mainnet/invoice.macaroon (invoice.macaroon is recommended) + +Instead of the path to the macaroon and cert files you can also provide the hex strings: + +* `lnd-cert`: LND TLS cert as HEX string. +* `lnd-macaroon`: LND macaroon file. (invoice.macaroon is recommended) #### Other configuration * `static-path`: Path to a folder that you want to serve with LnMe (e.g. /home/bitcoin/lnme/website). Use this if you want to customize your ⚡website. default: disabled * `disable-website`: Disable the default LnMe website. Disable the website if you only want to embed the LnMe widget on your existing website. * `disable-cors`: Disable CORS headers. (default: false) -* `bind`: Host and port to listen on. (default: :1323) +* `port`: Port to listen on. (default: 1323) * `request-limit`: Limit the allowed requests per second. (default: 5) +Depending on your deployment needs LnMe can be configured using the following options: + +1. Command line flags +2. Environment variables +3. Config TOML file + #### Examples: +##### Command line flags: + $ lnme --help - $ lnme --address=lndhost.com:10009 --bind=localhost:4711 + $ lnme --lnd-address=lndhost.com:10009 --port=4711 $ lnme --disable-website +##### TOML config file + +See [config.toml.example](./toml.config.example) for an example file. + + $ lnme --config=/path/to/config.toml + +##### Environment variables + +All environment variables must be prefixed by `LNME_` use `_` instead of `-` + + $ LNME_LND_ADDRESS=127.0.0.1:10005 lnme + ### Deployment diff --git a/config.toml.example b/config.toml.example index d99c4ac..b7a1131 100644 --- a/config.toml.example +++ b/config.toml.example @@ -1,12 +1,11 @@ -disable_website = false -disable_cors = false -request_limit = 5 +disable-website = false +disable-cors = false +request-limit = 5 port = "1323" -static_path = "" # Blank means disabled +static-path = "" # Blank means disabled -[lnd] -address = "127.0.0.1:10009" -cert = "TLS cert as hex" -cert_path = "Alternative to cert. Path to TLS cert file" -macaroon = "Macaroon as hex" -macaroon_path = "Alternative to macaroon. Path to macaroon file" \ No newline at end of file +lnd-address = "127.0.0.1:10009" +lnd-cert = "TLS cert as hex" +lnd-cert-path = "Alternative to cert. Path to TLS cert file" +lnd-macaroon = "Macaroon as hex" +lnd-macaroon-path = "Alternative to macaroon. Path to macaroon file" \ No newline at end of file diff --git a/lnme.go b/lnme.go index b7b3d66..43d6737 100644 --- a/lnme.go +++ b/lnme.go @@ -46,10 +46,10 @@ func main() { e := echo.New() // Serve static files if configured - if cfg.String("static_path") != "" { - e.Static("/", cfg.String("static_path")) + if cfg.String("static-path") != "" { + e.Static("/", cfg.String("static-path")) // Serve default page - } else if !cfg.Bool("disable_website") { + } else if !cfg.Bool("disable-website") { rootBox := rice.MustFindBox("files/root") indexPage, err := rootBox.String("index.html") if err == nil { @@ -66,7 +66,7 @@ func main() { e.GET("/lnme/*", echo.WrapHandler(http.StripPrefix("/lnme/", assetHandler))) // CORS settings - if !cfg.Bool("disable_cors") { + if !cfg.Bool("disable-cors") { e.Use(middleware.CORS()) } @@ -74,19 +74,19 @@ func main() { e.Use(middleware.Recover()) // Request limit per second. DoS protection - if cfg.Int("request_limit") > 0 { - limiter := tollbooth.NewLimiter(cfg.Float64("request_limit"), nil) + if cfg.Int("request-limit") > 0 { + limiter := tollbooth.NewLimiter(cfg.Float64("request-limit"), nil) e.Use(LimitMiddleware(limiter)) } // Setup lightning client - stdOutLogger.Printf("Connecting to %s", cfg.String("lnd.address")) + stdOutLogger.Printf("Connecting to %s", cfg.String("lnd-address")) lndOptions := ln.LNDoptions{ - Address: cfg.String("lnd.address"), - CertFile: cfg.String("lnd.cert_path"), - CertHex: cfg.String("lnd.cert"), - MacaroonFile: cfg.String("lnd.macaroon_path"), - MacaroonHex: cfg.String("lnd.macaroon"), + Address: cfg.String("lnd-address"), + CertFile: cfg.String("lnd-cert-path"), + CertHex: cfg.String("lnd-cert"), + MacaroonFile: cfg.String("lnd-macaroon-path"), + MacaroonHex: cfg.String("lnd-macaroon"), } lnClient, err := ln.NewLNDclient(lndOptions) if err != nil { @@ -148,13 +148,13 @@ func LoadConfig() *koanf.Koanf { k := koanf.New(".") f := flag.NewFlagSet("LnMe", flag.ExitOnError) - f.String("lnd.address", "localhost:10009", "The host and port of the LND gRPC server.") - f.String("lnd.macaroon_path", "~/.lnd/data/chain/bitcoin/mainnet/invoice.macaroon", "Path to the LND macaroon file.") - f.String("lnd.cert_path", "~/.lnd/tls.cert", "Path to the LND tls.cert file.") - f.Bool("disable_website", false, "Disable default embedded website.") - f.Bool("disable_cors", false, "Disable CORS headers.") - f.Float64("request_limit", 5, "Request limit per second.") - f.String("static_path", "", "Path to a static assets directory.") + f.String("lnd-address", "localhost:10009", "The host and port of the LND gRPC server.") + f.String("lnd-macaroon-path", "~/.lnd/data/chain/bitcoin/mainnet/invoice.macaroon", "Path to the LND macaroon file.") + f.String("lnd-cert-path", "~/.lnd/tls.cert", "Path to the LND tls.cert file.") + f.Bool("disable-website", false, "Disable default embedded website.") + f.Bool("disable-cors", false, "Disable CORS headers.") + f.Float64("request-limit", 5, "Request limit per second.") + f.String("static-path", "", "Path to a static assets directory.") f.String("port", "1323", "Port to bind on.") var configPath string f.StringVar(&configPath, "config", "config.toml", "Path to a .toml config file.") @@ -167,8 +167,7 @@ func LoadConfig() *koanf.Koanf { // Load config from environment variables k.Load(env.Provider("LNME_", ".", func(s string) string { - return strings.Replace(strings.ToLower( - strings.TrimPrefix(s, "LNME_")), "_", ".", -1) + return strings.Replace(strings.ToLower(strings.TrimPrefix(s, "LNME_")), "_", "-", -1) }), nil) // Load config from file if available