diff --git a/server/core/server.go b/server/core/server.go index 7d1edc0d..44647f82 100644 --- a/server/core/server.go +++ b/server/core/server.go @@ -4,10 +4,34 @@ import ( "fmt" "gin-vue-admin/global" "gin-vue-admin/initialize" + "github.com/fvbock/endless" + "github.com/gin-gonic/gin" "net/http" + "runtime" "time" ) +type server interface { + ListenAndServe() error +} + +func initServer(address string, router *gin.Engine) server { + if runtime.GOOS == "windows" { + return &http.Server{ + Addr: address, + Handler: router, + ReadTimeout: 10 * time.Second, + WriteTimeout: 10 * time.Second, + MaxHeaderBytes: 1 << 20, + } + } + s := endless.NewServer(address, router) + s.ReadHeaderTimeout = 10 * time.Millisecond + s.WriteTimeout = 10 * time.Second + s.MaxHeaderBytes = 1 << 20 + return s +} + func RunWindowsServer() { if global.GVA_CONFIG.System.UseMultipoint { // 初始化redis服务 @@ -20,13 +44,7 @@ func RunWindowsServer() { // end 插件描述 address := fmt.Sprintf(":%d", global.GVA_CONFIG.System.Addr) - s := &http.Server{ - Addr: address, - Handler: Router, - ReadTimeout: 10 * time.Second, - WriteTimeout: 10 * time.Second, - MaxHeaderBytes: 1 << 20, - } + s := initServer(address, Router) // 保证文本顺序输出 // In order to ensure that the text order output can be deleted time.Sleep(10 * time.Microsecond) @@ -35,6 +53,6 @@ func RunWindowsServer() { fmt.Printf(`欢迎使用 Gin-Vue-Admin 默认自动化文档地址:http://127.0.0.1%s/swagger/index.html 默认前端文件运行地址:http://127.0.0.1:8080 -`, s.Addr) +`, address) global.GVA_LOG.Error(s.ListenAndServe()) }