From 5e275b106c09a8edd91db63007a72b21abc60b09 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Sat, 9 Sep 2023 22:52:50 +0200 Subject: [PATCH] Use PORT from environment --- server.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server.go b/server.go index 9fb4e66..b0481aa 100644 --- a/server.go +++ b/server.go @@ -8,8 +8,10 @@ import ( "os/exec" "strings" + "github.com/joho/godotenv" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" + "github.com/namsral/flag" ) var ( @@ -18,6 +20,7 @@ var ( COMMIT_LONG_SHA string COMMIT_SHORT_SHA string VERSION string + PORT int ) func execCmd(name string, args ...string) string { @@ -30,6 +33,12 @@ func execCmd(name string, args ...string) string { } func init() { + err := godotenv.Load() + if err != nil { + log.Fatal("Error loading .env file") + } + flag.IntVar(&PORT, "PORT", 4321, "Server port") + flag.Parse() e = echo.New() t = &Template{ templates: template.Must(template.ParseGlob("template/*.html")), @@ -54,7 +63,7 @@ func main() { })) e.Use(sessionHandler) e.HTTPErrorHandler = httpErrorHandler - err := e.Start(":8080") + err := e.Start(fmt.Sprintf("%s:%d", "127.0.0.1", PORT)) if err != http.ErrServerClosed { log.Fatal(err) }