1
1
mirror of https://github.com/bumi/lntip synced 2026-02-17 06:27:49 +00:00

1 Commits
1.2.0 ... 1.3.0

Author SHA1 Message Date
Gregor Pogačnik
3200622b97 Possibility to specify listening IP (#17) 2021-09-30 18:07:43 +02:00

21
lnme.go
View File

@@ -24,6 +24,8 @@ import (
"github.com/labstack/echo/v4/middleware"
)
const DEFAULT_LISTEN = ":1323"
// Middleware for request limited to prevent too many requests
// TODO: move to file
func LimitMiddleware(lmt *limiter.Limiter) echo.MiddlewareFunc {
@@ -185,10 +187,24 @@ func main() {
})
port := cfg.String("port")
// Special case for PORT instead of LNME_PORT due to cloud-providers
if os.Getenv("PORT") != "" {
port = os.Getenv("PORT")
}
e.Logger.Fatal(e.Start(":" + port))
listen := cfg.String("listen")
if listen != "" && port != "" {
log.Fatalf("Port and listen options are mutually exclusive, please just use listen.")
}
if listen == "" {
if port != "" {
stdOutLogger.Printf("Please use listen instead of deprecated port setting.")
listen = fmt.Sprintf(":%s", port)
} else {
listen = DEFAULT_LISTEN
}
}
e.Logger.Fatal(e.Start(listen))
}
func LoadConfig() *koanf.Koanf {
@@ -203,7 +219,8 @@ func LoadConfig() *koanf.Koanf {
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.")
f.String("port", "", "Port to bind on (deprecated - use listen).")
f.String("listen", "", fmt.Sprintf("Address to bind on. (default \"%s\")", DEFAULT_LISTEN))
var configPath string
f.StringVar(&configPath, "config", "config.toml", "Path to a .toml config file.")
f.Parse(os.Args[1:])