Skip to content

Commit 990fd1f

Browse files
authored
非Windows操作系统使用endless启动服务
1 parent a9961f1 commit 990fd1f

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

server/core/server.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,34 @@ import (
44
"fmt"
55
"gin-vue-admin/global"
66
"gin-vue-admin/initialize"
7+
"github.com/fvbock/endless"
8+
"github.com/gin-gonic/gin"
79
"net/http"
10+
"runtime"
811
"time"
912
)
1013

14+
type server interface {
15+
ListenAndServe() error
16+
}
17+
18+
func initServer(address string, router *gin.Engine) server {
19+
if runtime.GOOS == "windows" {
20+
return &http.Server{
21+
Addr: address,
22+
Handler: router,
23+
ReadTimeout: 10 * time.Second,
24+
WriteTimeout: 10 * time.Second,
25+
MaxHeaderBytes: 1 << 20,
26+
}
27+
}
28+
s := endless.NewServer(address, router)
29+
s.ReadHeaderTimeout = 10 * time.Millisecond
30+
s.WriteTimeout = 10 * time.Second
31+
s.MaxHeaderBytes = 1 << 20
32+
return s
33+
}
34+
1135
func RunWindowsServer() {
1236
if global.GVA_CONFIG.System.UseMultipoint {
1337
// 初始化redis服务
@@ -20,13 +44,7 @@ func RunWindowsServer() {
2044
// end 插件描述
2145

2246
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-
}
47+
s := initServer(address, Router)
3048
// 保证文本顺序输出
3149
// In order to ensure that the text order output can be deleted
3250
time.Sleep(10 * time.Microsecond)
@@ -35,6 +53,6 @@ func RunWindowsServer() {
3553
fmt.Printf(`欢迎使用 Gin-Vue-Admin
3654
默认自动化文档地址:http://127.0.0.1%s/swagger/index.html
3755
默认前端文件运行地址:http://127.0.0.1:8080
38-
`, s.Addr)
56+
`, address)
3957
global.GVA_LOG.Error(s.ListenAndServe())
4058
}

0 commit comments

Comments
 (0)