使用配置文件指定端口

This commit is contained in:
2023-04-12 15:52:02 +08:00
parent e9878aa437
commit 6aa48128a3

View File

@@ -17,6 +17,7 @@ import (
"git.satori.love/gameui/webp/models"
_ "github.com/go-sql-driver/mysql"
"github.com/milvus-io/milvus-sdk-go/v2/entity"
"github.com/spf13/viper"
)
// string 转换为 int, 如果转换失败则返回默认值
@@ -362,6 +363,8 @@ func main() {
w.Write(data)
})
log.Println("Server is running at http://localhost:6001")
http.ListenAndServe(":6001", nil)
// 从Viper中读取配置
port := viper.GetString("server.port")
log.Println("Server is running at http://localhost:" + port)
http.ListenAndServe(":"+port, nil)
}