File tree Expand file tree Collapse file tree 4 files changed +43
-9
lines changed Expand file tree Collapse file tree 4 files changed +43
-9
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,13 @@ import (
44 "fmt"
55 "gin-vue-admin/global"
66 "gin-vue-admin/initialize"
7- "net/http"
87 "time"
98)
109
10+ type server interface {
11+ ListenAndServe () error
12+ }
13+
1114func RunWindowsServer () {
1215 if global .GVA_CONFIG .System .UseMultipoint {
1316 // 初始化redis服务
@@ -20,13 +23,7 @@ func RunWindowsServer() {
2023 // end 插件描述
2124
2225 address := fmt .Sprintf (":%d" , global .GVA_CONFIG .System .Addr )
23- s := & http.Server {
24- Addr : address ,
25- Handler : Router ,
26- ReadTimeout : 10 * time .Second ,
27- WriteTimeout : 10 * time .Second ,
28- MaxHeaderBytes : 1 << 20 ,
29- }
26+ s := initServer (address , Router )
3027 // 保证文本顺序输出
3128 // In order to ensure that the text order output can be deleted
3229 time .Sleep (10 * time .Microsecond )
@@ -35,6 +32,6 @@ func RunWindowsServer() {
3532 fmt .Printf (`欢迎使用 Gin-Vue-Admin
3633 默认自动化文档地址:http://127.0.0.1%s/swagger/index.html
3734 默认前端文件运行地址:http://127.0.0.1:8080
38- ` , s . Addr )
35+ ` , address )
3936 global .GVA_LOG .Error (s .ListenAndServe ())
4037}
Original file line number Diff line number Diff line change 1+ // +build !windows
2+
3+ package core
4+
5+ import (
6+ "github.com/fvbock/endless"
7+ "github.com/gin-gonic/gin"
8+ "time"
9+ )
10+
11+ func initServer (address string , router * gin.Engine ) server {
12+ s := endless .NewServer (address , router )
13+ s .ReadHeaderTimeout = 10 * time .Millisecond
14+ s .WriteTimeout = 10 * time .Second
15+ s .MaxHeaderBytes = 1 << 20
16+ return s
17+ }
Original file line number Diff line number Diff line change 1+ // +build windows
2+
3+ package core
4+
5+ import (
6+ "github.com/gin-gonic/gin"
7+ "net/http"
8+ "time"
9+ )
10+
11+ func initServer (address string , router * gin.Engine ) server {
12+ return & http.Server {
13+ Addr : address ,
14+ Handler : router ,
15+ ReadTimeout : 10 * time .Second ,
16+ WriteTimeout : 10 * time .Second ,
17+ MaxHeaderBytes : 1 << 20 ,
18+ }
19+ }
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ require (
99 github.com/dgrijalva/jwt-go v3.2.0+incompatible
1010 github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
1111 github.com/fsnotify/fsnotify v1.4.9
12+ github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6
1213 github.com/gin-gonic/gin v1.6.3
1314 github.com/go-openapi/spec v0.19.7 // indirect
1415 github.com/go-openapi/swag v0.19.8 // indirect
You can’t perform that action at this time.
0 commit comments