From 9a0c74e04c0df77dffb49fab11e0b9d2a023a011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=BF=97=E4=BC=9F?= Date: Tue, 30 Jun 2020 12:43:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DWindows=E4=B8=8B=E7=BC=96?= =?UTF-8?q?=E8=AF=91endless=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/core/server.go | 21 --------------------- server/core/server_other.go | 17 +++++++++++++++++ server/core/server_win.go | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 21 deletions(-) create mode 100644 server/core/server_other.go create mode 100644 server/core/server_win.go diff --git a/server/core/server.go b/server/core/server.go index 44647f82..f855aede 100644 --- a/server/core/server.go +++ b/server/core/server.go @@ -4,10 +4,6 @@ import ( "fmt" "gin-vue-admin/global" "gin-vue-admin/initialize" - "github.com/fvbock/endless" - "github.com/gin-gonic/gin" - "net/http" - "runtime" "time" ) @@ -15,23 +11,6 @@ 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服务 diff --git a/server/core/server_other.go b/server/core/server_other.go new file mode 100644 index 00000000..67cdac75 --- /dev/null +++ b/server/core/server_other.go @@ -0,0 +1,17 @@ +// +build !windows + +package core + +import ( + "github.com/fvbock/endless" + "github.com/gin-gonic/gin" + "time" +) + +func initServer(address string, router *gin.Engine) server { + s := endless.NewServer(address, router) + s.ReadHeaderTimeout = 10 * time.Millisecond + s.WriteTimeout = 10 * time.Second + s.MaxHeaderBytes = 1 << 20 + return s +} \ No newline at end of file diff --git a/server/core/server_win.go b/server/core/server_win.go new file mode 100644 index 00000000..501128af --- /dev/null +++ b/server/core/server_win.go @@ -0,0 +1,19 @@ +// +build windows + +package core + +import ( + "github.com/gin-gonic/gin" + "net/http" + "time" +) + +func initServer(address string, router *gin.Engine) server { + return &http.Server{ + Addr: address, + Handler: router, + ReadTimeout: 10 * time.Second, + WriteTimeout: 10 * time.Second, + MaxHeaderBytes: 1 << 20, + } +} \ No newline at end of file