mirror of
https://github.com/bumi/lntip
synced 2025-08-18 09:10:52 +00:00
Sorry go fmt
This commit is contained in:
parent
f81937a7dd
commit
77a96bdd83
84
lnme.go
84
lnme.go
@ -1,22 +1,22 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"flag"
|
||||||
"flag"
|
"github.com/GeertJohan/go.rice"
|
||||||
|
"github.com/bumi/lnme/ln"
|
||||||
|
"github.com/didip/tollbooth/v6"
|
||||||
|
"github.com/didip/tollbooth/v6/limiter"
|
||||||
|
"github.com/knadh/koanf"
|
||||||
|
"github.com/knadh/koanf/parsers/toml"
|
||||||
|
"github.com/knadh/koanf/providers/basicflag"
|
||||||
|
"github.com/knadh/koanf/providers/env"
|
||||||
|
"github.com/knadh/koanf/providers/file"
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/labstack/echo/v4/middleware"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"github.com/bumi/lnme/ln"
|
"strings"
|
||||||
"github.com/GeertJohan/go.rice"
|
|
||||||
"github.com/didip/tollbooth/v6"
|
|
||||||
"github.com/didip/tollbooth/v6/limiter"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"github.com/labstack/echo/v4/middleware"
|
|
||||||
"github.com/knadh/koanf"
|
|
||||||
"github.com/knadh/koanf/providers/file"
|
|
||||||
"github.com/knadh/koanf/parsers/toml"
|
|
||||||
"github.com/knadh/koanf/providers/env"
|
|
||||||
"github.com/knadh/koanf/providers/basicflag"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Middleware for request limited to prevent too many requests
|
// Middleware for request limited to prevent too many requests
|
||||||
@ -41,9 +41,9 @@ type Invoice struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cfg := LoadConfig()
|
cfg := LoadConfig()
|
||||||
|
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
|
|
||||||
// Serve static files if configured
|
// Serve static files if configured
|
||||||
if cfg.String("static_path") != "" {
|
if cfg.String("static_path") != "" {
|
||||||
@ -66,7 +66,7 @@ func main() {
|
|||||||
e.GET("/lnme/*", echo.WrapHandler(http.StripPrefix("/lnme/", assetHandler)))
|
e.GET("/lnme/*", echo.WrapHandler(http.StripPrefix("/lnme/", assetHandler)))
|
||||||
|
|
||||||
// CORS settings
|
// CORS settings
|
||||||
if !cfg.Bool("disable_cors") {
|
if !cfg.Bool("disable_cors") {
|
||||||
e.Use(middleware.CORS())
|
e.Use(middleware.CORS())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,11 +82,11 @@ func main() {
|
|||||||
// Setup lightning client
|
// Setup lightning client
|
||||||
stdOutLogger.Printf("Connecting to %s", cfg.String("lnd.address"))
|
stdOutLogger.Printf("Connecting to %s", cfg.String("lnd.address"))
|
||||||
lndOptions := ln.LNDoptions{
|
lndOptions := ln.LNDoptions{
|
||||||
Address: cfg.String("lnd.address"),
|
Address: cfg.String("lnd.address"),
|
||||||
CertFile: cfg.String("lnd.cert_path"),
|
CertFile: cfg.String("lnd.cert_path"),
|
||||||
CertHex: cfg.String("lnd.cert"),
|
CertHex: cfg.String("lnd.cert"),
|
||||||
MacaroonFile: cfg.String("lnd.macaroon_path"),
|
MacaroonFile: cfg.String("lnd.macaroon_path"),
|
||||||
MacaroonHex: cfg.String("lnd.macaroon"),
|
MacaroonHex: cfg.String("lnd.macaroon"),
|
||||||
}
|
}
|
||||||
lnClient, err := ln.NewLNDclient(lndOptions)
|
lnClient, err := ln.NewLNDclient(lndOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -141,44 +141,44 @@ func main() {
|
|||||||
return c.JSON(http.StatusOK, "pong")
|
return c.JSON(http.StatusOK, "pong")
|
||||||
})
|
})
|
||||||
|
|
||||||
e.Logger.Fatal(e.Start(":" + cfg.String("port")))
|
e.Logger.Fatal(e.Start(":" + cfg.String("port")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadConfig() *koanf.Koanf {
|
func LoadConfig() *koanf.Koanf {
|
||||||
k := koanf.New(".")
|
k := koanf.New(".")
|
||||||
|
|
||||||
f := flag.NewFlagSet("LnMe", flag.ExitOnError)
|
f := flag.NewFlagSet("LnMe", flag.ExitOnError)
|
||||||
f.String("lnd.address", "localhost:10009", "The host and port of the LND gRPC server.")
|
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.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.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_website", false, "Disable default embedded website.")
|
||||||
f.Bool("disable_cors", false, "Disable CORS headers.")
|
f.Bool("disable_cors", false, "Disable CORS headers.")
|
||||||
f.Float64("request_limit", 5, "Request limit per second.")
|
f.Float64("request_limit", 5, "Request limit per second.")
|
||||||
f.String("static_path", "", "Path to a static assets directory.")
|
f.String("static_path", "", "Path to a static assets directory.")
|
||||||
f.String("port", "1323", "Port to bind on.")
|
f.String("port", "1323", "Port to bind on.")
|
||||||
var configPath string
|
var configPath string
|
||||||
f.StringVar(&configPath, "config", "config.toml", "Path to a .toml config file.")
|
f.StringVar(&configPath, "config", "config.toml", "Path to a .toml config file.")
|
||||||
f.Parse(os.Args[1:])
|
f.Parse(os.Args[1:])
|
||||||
|
|
||||||
// Load config from flags, including defaults
|
// Load config from flags, including defaults
|
||||||
if err := k.Load(basicflag.Provider(f, "."), nil); err != nil {
|
if err := k.Load(basicflag.Provider(f, "."), nil); err != nil {
|
||||||
log.Fatalf("Error loading config: %v", err)
|
log.Fatalf("Error loading config: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load config from environment variables
|
// Load config from environment variables
|
||||||
k.Load(env.Provider("LNME_", ".", func(s string) string {
|
k.Load(env.Provider("LNME_", ".", func(s string) string {
|
||||||
return strings.Replace(strings.ToLower(
|
return strings.Replace(strings.ToLower(
|
||||||
strings.TrimPrefix(s, "LNME_")), "_", ".", -1)
|
strings.TrimPrefix(s, "LNME_")), "_", ".", -1)
|
||||||
}), nil)
|
}), nil)
|
||||||
|
|
||||||
// Load config from file if available
|
// Load config from file if available
|
||||||
if configPath != "" {
|
if configPath != "" {
|
||||||
if _, err := os.Stat(configPath); err == nil {
|
if _, err := os.Stat(configPath); err == nil {
|
||||||
if err := k.Load(file.Provider(configPath), toml.Parser()); err != nil {
|
if err := k.Load(file.Provider(configPath), toml.Parser()); err != nil {
|
||||||
log.Fatalf("Error loading config file: %v", err)
|
log.Fatalf("Error loading config file: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return k
|
return k
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user