From 085f11c43c1a73eec0874fb88a7d29f8683ce8ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=BF=97=E4=BC=9F?= Date: Thu, 25 Jun 2020 18:52:07 +0800 Subject: [PATCH 1/4] update go.mod --- server/go.mod | 1 - 1 file changed, 1 deletion(-) diff --git a/server/go.mod b/server/go.mod index b0985872..ebfebf31 100644 --- a/server/go.mod +++ b/server/go.mod @@ -6,7 +6,6 @@ require ( github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 github.com/casbin/casbin v1.9.1 github.com/casbin/gorm-adapter v1.0.0 - github.com/dchest/captcha v0.0.0-20170622155422-6a29415a8364 github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/fsnotify/fsnotify v1.4.9 From 178b028a9b429275833953b47bb01293aea9a298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=BF=97=E4=BC=9F?= Date: Thu, 25 Jun 2020 18:53:23 +0800 Subject: [PATCH 2/4] update go.mod --- server/go.mod | 1 + 1 file changed, 1 insertion(+) diff --git a/server/go.mod b/server/go.mod index ebfebf31..33cd9422 100644 --- a/server/go.mod +++ b/server/go.mod @@ -9,6 +9,7 @@ require ( github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/fsnotify/fsnotify v1.4.9 + github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6 github.com/gin-gonic/gin v1.6.3 github.com/go-openapi/spec v0.19.7 // indirect github.com/go-openapi/swag v0.19.8 // indirect From 90f5337537a477226a8f4b48ccf77192f977a48d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=BF=97=E4=BC=9F?= Date: Thu, 25 Jun 2020 19:02:09 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E9=9D=9EWindows=E6=93=8D=E4=BD=9C=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E4=BD=BF=E7=94=A8endless=E5=90=AF=E5=8A=A8=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/core/server.go | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) 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()) } From 63f2886de69382bbb18f3cb336693b64c7936000 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 4/4] =?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