feat: Read PORT envvar

This commit is contained in:
pan93412 2023-04-09 16:54:56 +08:00
parent f9f378e7eb
commit cb0bdf9028
No known key found for this signature in database
GPG Key ID: 42154B1B1CFE3377

10
main.go
View File

@ -8,6 +8,7 @@ import (
"log"
"math/rand"
"net/http"
"os"
"strings"
"time"
@ -115,7 +116,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) {
@ -225,5 +225,11 @@ func main() {
}
}
})
r.Run(":1188") // listen and serve on 0.0.0.0:1188
port, ok := os.LookupEnv("PORT")
if ok {
r.Run(":" + port)
} else {
r.Run(":1188") // listen and serve on 0.0.0.0:1188
}
}