feat: production mode

This commit is contained in:
httpjamesm 2022-12-28 11:35:03 -05:00
parent 504144c94b
commit 26c7a5f5ee

25
main.go
View File

@ -11,6 +11,21 @@ import (
func main() { 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 := gin.Default()
r.LoadHTMLGlob("templates/*") r.LoadHTMLGlob("templates/*")
@ -32,15 +47,5 @@ func main() {
r.GET("/questions/:id/:title", routes.ViewQuestion) 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)) r.Run(fmt.Sprintf("%s:%s", host, port))
} }