From a2959a01af4b6987ba53ee9d62e312609456c369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=8E=E6=98=8E?= Date: Sat, 1 Jul 2023 21:45:00 +0800 Subject: [PATCH] feat: read port envvar (#53) Co-authored-by: pan93412 --- main.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index b7fbe03..f06aa7b 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "log" "math/rand" "net/http" + "os" "strings" "time" @@ -130,7 +131,6 @@ func main() { "code": 200, "message": "DeepL Free API, Made by sjlleo and missuo. Go to /translate with POST. http://github.com/OwO-Network/DeepLX", }) - }) r.POST("/translate", func(c *gin.Context) { @@ -250,6 +250,13 @@ func main() { } } }) - // by default, listen and serve on 0.0.0.0:1188 - r.Run(fmt.Sprintf(":%v", port)) + + envPort, ok := os.LookupEnv("PORT") + if ok { + r.Run(":" + envPort) + } else { + // by default, listen and serve on 0.0.0.0:1188 + r.Run(fmt.Sprintf(":%v", port)) + } + }