Browse Source

Merge pull request #128 from JuwanXu/develop

非 Windows 操作系统使用endless启动服务
main
蒋吉兆 4 years ago
committed by GitHub
parent
commit
808795f607
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      server/core/server.go
  2. 17
      server/core/server_other.go
  3. 19
      server/core/server_win.go
  4. 2
      server/go.mod

15
server/core/server.go

@ -4,10 +4,13 @@ import (
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/initialize"
"net/http"
"time"
)
type server interface {
ListenAndServe() error
}
func RunWindowsServer() {
if global.GVA_CONFIG.System.UseMultipoint {
// 初始化redis服务
@ -20,13 +23,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 +32,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())
}

17
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
}

19
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,
}
}

2
server/go.mod

@ -6,10 +6,10 @@ 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
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

Loading…
Cancel
Save