From fd6ca8b56ac10bf9ee822142a2494decba188ca4 Mon Sep 17 00:00:00 2001 From: httpjamesm Date: Wed, 28 Dec 2022 00:23:53 -0500 Subject: [PATCH] feat: host and port envs --- main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 42575a6..865ef37 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,8 @@ package main import ( "anonymousoverflow/src/middleware" "anonymousoverflow/src/routes" + "fmt" + "os" "github.com/gin-gonic/gin" ) @@ -30,5 +32,15 @@ func main() { r.GET("/questions/:id/:title", routes.ViewQuestion) - r.Run("localhost:8080") + host := os.Getenv("HOST") + if host == "" { + host = "0.0.0.0" + } + + port := os.Getenv("PORT") + if port == "" { + port = "8080" + } + + r.Run(fmt.Sprintf("%s:%s", host, port)) }