Browse Source

Accept port as a command line param

Alex Myasoedov 7 years ago
parent
commit
9c26469d81
1 changed files with 10 additions and 1 deletions
  1. 10 1
      main.go

+ 10 - 1
main.go

@@ -163,6 +163,15 @@ func NewApp() *gin.Engine {
 
 func main() {
 	r := NewApp()
+	port := "8080"
+	if len(os.Args) > 1 {
+		port = os.Args[1]
+	} else {
+		envPort := os.Getenv("PORT")
+		if len(envPort) > 0 {
+			port = envPort
+		}
+	}
 	log.Info("Started http://0.0.0.0:8080")
-	r.Run(":8080")
+	r.Run(fmt.Sprintf(":%s", port))
 }