Use PORT from environment
This commit is contained in:
parent
9440f58efe
commit
5e275b106c
11
server.go
11
server.go
|
@ -8,8 +8,10 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/labstack/echo/v4/middleware"
|
"github.com/labstack/echo/v4/middleware"
|
||||||
|
"github.com/namsral/flag"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -18,6 +20,7 @@ var (
|
||||||
COMMIT_LONG_SHA string
|
COMMIT_LONG_SHA string
|
||||||
COMMIT_SHORT_SHA string
|
COMMIT_SHORT_SHA string
|
||||||
VERSION string
|
VERSION string
|
||||||
|
PORT int
|
||||||
)
|
)
|
||||||
|
|
||||||
func execCmd(name string, args ...string) string {
|
func execCmd(name string, args ...string) string {
|
||||||
|
@ -30,6 +33,12 @@ func execCmd(name string, args ...string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
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()
|
e = echo.New()
|
||||||
t = &Template{
|
t = &Template{
|
||||||
templates: template.Must(template.ParseGlob("template/*.html")),
|
templates: template.Must(template.ParseGlob("template/*.html")),
|
||||||
|
@ -54,7 +63,7 @@ func main() {
|
||||||
}))
|
}))
|
||||||
e.Use(sessionHandler)
|
e.Use(sessionHandler)
|
||||||
e.HTTPErrorHandler = httpErrorHandler
|
e.HTTPErrorHandler = httpErrorHandler
|
||||||
err := e.Start(":8080")
|
err := e.Start(fmt.Sprintf("%s:%d", "127.0.0.1", PORT))
|
||||||
if err != http.ErrServerClosed {
|
if err != http.ErrServerClosed {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue