Skip to content

Commit 92f82af

Browse files
author
蒋吉兆
authored
Merge pull request #128 from JuwanXu/develop
非 Windows 操作系统使用endless启动服务
2 parents 4153eb9 + 9a0c74e commit 92f82af

File tree

4 files changed

+43
-10
lines changed

4 files changed

+43
-10
lines changed

server/core/server.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff 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+
1114
func 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
}

server/core/server_other.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

server/core/server_win.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}

server/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ require (
66
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
77
github.com/casbin/casbin v1.9.1
88
github.com/casbin/gorm-adapter v1.0.0
9-
github.com/dchest/captcha v0.0.0-20170622155422-6a29415a8364
109
github.com/dgrijalva/jwt-go v3.2.0+incompatible
1110
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
1211
github.com/fsnotify/fsnotify v1.4.9
12+
github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6
1313
github.com/gin-gonic/gin v1.6.3
1414
github.com/go-openapi/spec v0.19.7 // indirect
1515
github.com/go-openapi/swag v0.19.8 // indirect

0 commit comments

Comments
 (0)