feat: read port envvar (#53)

Co-authored-by: pan93412 <pan93412@gmail.com>
This commit is contained in:
明明 2023-07-01 21:45:00 +08:00 committed by GitHub
parent 7bf2bfca21
commit a2959a01af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

13
main.go
View File

@ -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))
}
}