增加windows系统兼容
parent
42beeb1c06
commit
ef775d84e9
|
@ -2,11 +2,10 @@ package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/fvbock/endless"
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"go.uber.org/zap"
|
||||||
"goweb-gin-demo/global"
|
"goweb-gin-demo/global"
|
||||||
"goweb-gin-demo/initialize"
|
"goweb-gin-demo/initialize"
|
||||||
"go.uber.org/zap"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -37,11 +36,3 @@ func RunServer() {
|
||||||
`, address)
|
`, address)
|
||||||
global.GLOBAL_LOG.Error(s.ListenAndServe().Error())
|
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
|
|
||||||
}
|
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -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,
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
[goweb-demo]2021/12/22 - 10:56:24.790 [34minfo[0m /Users/ymm/work/mygithub/goweb-gin-demo/server/initialize/router.go:49 router register success
|
||||||
|
[goweb-demo]2021/12/22 - 10:56:24.791 [34minfo[0m /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 [31merror[0m /Users/ymm/work/mygithub/goweb-gin-demo/server/core/server.go:38 accept tcp [::]:8981: use of closed network connection
|
Loading…
Reference in New Issue