增加windows系统兼容

master
ymm 2022-02-09 12:32:05 +08:00
parent 42beeb1c06
commit ef775d84e9
4 changed files with 44 additions and 10 deletions

View File

@ -2,11 +2,10 @@ package core
import (
"fmt"
"github.com/fvbock/endless"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"goweb-gin-demo/global"
"goweb-gin-demo/initialize"
"go.uber.org/zap"
"time"
)
@ -37,11 +36,3 @@ func RunServer() {
`, address)
global.GLOBAL_LOG.Error(s.ListenAndServe().Error())
}
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
}

View File

@ -0,0 +1,19 @@
//go:build !windows
// +build !windows
package core
import (
"time"
"github.com/fvbock/endless"
"github.com/gin-gonic/gin"
)
func initServer(address string, router *gin.Engine) server {
s := endless.NewServer(address, router)
s.ReadHeaderTimeout = 20 * time.Second
s.WriteTimeout = 20 * time.Second
s.MaxHeaderBytes = 1 << 20
return s
}

21
server/core/server_win.go Normal file
View File

@ -0,0 +1,21 @@
//go:build windows
// +build windows
package core
import (
"net/http"
"time"
"github.com/gin-gonic/gin"
)
func initServer(address string, router *gin.Engine) server {
return &http.Server{
Addr: address,
Handler: router,
ReadTimeout: 20 * time.Second,
WriteTimeout: 20 * time.Second,
MaxHeaderBytes: 1 << 20,
}
}

View File

@ -0,0 +1,3 @@
[goweb-demo]2021/12/22 - 10:56:24.790 info /Users/ymm/work/mygithub/goweb-gin-demo/server/initialize/router.go:49 router register success
[goweb-demo]2021/12/22 - 10:56:24.791 info /Users/ymm/work/mygithub/goweb-gin-demo/server/core/server.go:31 server run success on {"address": ":8981"}
[goweb-demo]2021/12/22 - 10:58:09.632 error /Users/ymm/work/mygithub/goweb-gin-demo/server/core/server.go:38 accept tcp [::]:8981: use of closed network connection