fixed #2 适配zeabur

PORT写死的时候不能用
This commit is contained in:
Sakurasan
2023-04-03 17:18:11 +08:00

View File

@@ -2,6 +2,7 @@ package main
import ( import (
"log" "log"
"net/http"
"opencatd-open/router" "opencatd-open/router"
"opencatd-open/store" "opencatd-open/store"
"os" "os"
@@ -22,7 +23,7 @@ func main() {
log.Println("new root token:", ntoken) log.Println("new root token:", ntoken)
return return
} }
port := os.Getenv("PORT")
r := gin.Default() r := gin.Default()
group := r.Group("/1") group := r.Group("/1")
{ {
@@ -59,6 +60,13 @@ func main() {
r.POST("/v1/chat/completions", router.HandleProy) r.POST("/v1/chat/completions", router.HandleProy)
r.GET("/v1/models", router.HandleProy) r.GET("/v1/models", router.HandleProy)
r.GET("/v1/dashboard/billing/credit_grants", router.HandleProy) r.GET("/v1/dashboard/billing/credit_grants", router.HandleProy)
r.GET("/", func(c *gin.Context) {
c.Writer.WriteHeader(http.StatusOK)
c.Writer.WriteString(`<h1><a href="https://github.com/mirrors2/opencatd-open" >opencatd-open</a> available</h1>Api-Keys:<a href=https://platform.openai.com/account/api-keys >https://platform.openai.com/account/api-keys</a>`)
})
r.Run(":80") if port == "" {
port = "80"
}
r.Run(":" + port)
} }