From 26c7a5f5ee4b983db4a4a6d4f888b5c8b95629ba Mon Sep 17 00:00:00 2001 From: httpjamesm Date: Wed, 28 Dec 2022 11:35:03 -0500 Subject: [PATCH] feat: production mode --- main.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 865ef37..d90dbea 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,21 @@ import ( func main() { + host := os.Getenv("HOST") + if host == "" { + host = "0.0.0.0" + } + + port := os.Getenv("PORT") + if port == "" { + port = "8080" + } + + if os.Getenv("DEV") != "true" { + gin.SetMode(gin.ReleaseMode) + fmt.Printf("Running in production mode. Listening on %s:%s.", host, port) + } + r := gin.Default() r.LoadHTMLGlob("templates/*") @@ -32,15 +47,5 @@ func main() { r.GET("/questions/:id/:title", routes.ViewQuestion) - 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)) }