mirror of
https://github.com/astaxie/beego.git
synced 2024-11-23 01:20:54 +00:00
sync beeApp.Server to graceful
This commit is contained in:
parent
59c1e74e13
commit
185089299c
11
app.go
11
app.go
@ -78,15 +78,19 @@ func (app *App) Run() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if Graceful {
|
if Graceful {
|
||||||
|
app.Server.Addr = addr
|
||||||
|
app.Server.Handler = app.Handlers
|
||||||
|
app.Server.ReadTimeout = time.Duration(HttpServerTimeOut) * time.Second
|
||||||
|
app.Server.WriteTimeout = time.Duration(HttpServerTimeOut) * time.Second
|
||||||
if EnableHttpTLS {
|
if EnableHttpTLS {
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(20 * time.Microsecond)
|
time.Sleep(20 * time.Microsecond)
|
||||||
if HttpsPort != 0 {
|
if HttpsPort != 0 {
|
||||||
addr = fmt.Sprintf("%s:%d", HttpAddr, HttpsPort)
|
addr = fmt.Sprintf("%s:%d", HttpAddr, HttpsPort)
|
||||||
|
app.Server.Addr = addr
|
||||||
}
|
}
|
||||||
server := grace.NewServer(addr, app.Handlers)
|
server := grace.NewServer(addr, app.Handlers)
|
||||||
server.Server.ReadTimeout = time.Duration(HttpServerTimeOut) * time.Second
|
server.Server = app.Server
|
||||||
server.Server.WriteTimeout = time.Duration(HttpServerTimeOut) * time.Second
|
|
||||||
err := server.ListenAndServeTLS(HttpCertFile, HttpKeyFile)
|
err := server.ListenAndServeTLS(HttpCertFile, HttpKeyFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
BeeLogger.Critical("ListenAndServeTLS: ", err)
|
BeeLogger.Critical("ListenAndServeTLS: ", err)
|
||||||
@ -98,8 +102,7 @@ func (app *App) Run() {
|
|||||||
if EnableHttpListen {
|
if EnableHttpListen {
|
||||||
go func() {
|
go func() {
|
||||||
server := grace.NewServer(addr, app.Handlers)
|
server := grace.NewServer(addr, app.Handlers)
|
||||||
server.Server.ReadTimeout = time.Duration(HttpServerTimeOut) * time.Second
|
server.Server = app.Server
|
||||||
server.Server.WriteTimeout = time.Duration(HttpServerTimeOut) * time.Second
|
|
||||||
if ListenTCP4 && HttpAddr == "" {
|
if ListenTCP4 && HttpAddr == "" {
|
||||||
server.Network = "tcp4"
|
server.Network = "tcp4"
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type graceServer struct {
|
type graceServer struct {
|
||||||
http.Server
|
*http.Server
|
||||||
GraceListener net.Listener
|
GraceListener net.Listener
|
||||||
SignalHooks map[int]map[os.Signal][]func()
|
SignalHooks map[int]map[os.Signal][]func()
|
||||||
tlsInnerListener *graceListener
|
tlsInnerListener *graceListener
|
||||||
@ -151,7 +151,7 @@ func NewServer(addr string, handler http.Handler) (srv *graceServer) {
|
|||||||
state: STATE_INIT,
|
state: STATE_INIT,
|
||||||
Network: "tcp",
|
Network: "tcp",
|
||||||
}
|
}
|
||||||
|
srv.Server = &http.Server{}
|
||||||
srv.Server.Addr = addr
|
srv.Server.Addr = addr
|
||||||
srv.Server.ReadTimeout = DefaultReadTimeOut
|
srv.Server.ReadTimeout = DefaultReadTimeOut
|
||||||
srv.Server.WriteTimeout = DefaultWriteTimeOut
|
srv.Server.WriteTimeout = DefaultWriteTimeOut
|
||||||
|
Loading…
Reference in New Issue
Block a user