mirror of https://github.com/gin-gonic/gin.git
graceful shutdown run function initial setup
Change-Id: I7dca9f7117e54954ad12f5c04f4dd81315008d0e
This commit is contained in:
parent
f4bc259de3
commit
c844dc8299
7
gin.go
7
gin.go
|
@ -15,6 +15,7 @@ import (
|
|||
|
||||
"github.com/gin-gonic/gin/internal/bytesconv"
|
||||
"github.com/gin-gonic/gin/render"
|
||||
"github.com/kuangchanglang/graceful"
|
||||
)
|
||||
|
||||
const defaultMultipartMemory = 32 << 20 // 32 MB
|
||||
|
@ -114,6 +115,7 @@ type Engine struct {
|
|||
pool sync.Pool
|
||||
trees methodTrees
|
||||
maxParams uint16
|
||||
server *graceful.Server
|
||||
}
|
||||
|
||||
var _ IRouter = &Engine{}
|
||||
|
@ -311,6 +313,11 @@ func (engine *Engine) Run(addr ...string) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// RunGracefully supports graceful shutdown using graceful 3rd party library
|
||||
func (engine *Engine) RunGracefully(addr ...string) error {
|
||||
return engine.server.Run()
|
||||
}
|
||||
|
||||
// RunTLS attaches the router to a http.Server and starts listening and serving HTTPS (secure) requests.
|
||||
// It is a shortcut for http.ListenAndServeTLS(addr, certFile, keyFile, router)
|
||||
// Note: this method will block the calling goroutine indefinitely unless an error happens.
|
||||
|
|
1
go.mod
1
go.mod
|
@ -7,6 +7,7 @@ require (
|
|||
github.com/go-playground/validator/v10 v10.4.1
|
||||
github.com/golang/protobuf v1.3.3
|
||||
github.com/json-iterator/go v1.1.9
|
||||
github.com/kuangchanglang/graceful v1.0.2
|
||||
github.com/mattn/go-isatty v0.0.12
|
||||
github.com/stretchr/testify v1.4.0
|
||||
github.com/ugorji/go/codec v1.1.7
|
||||
|
|
2
go.sum
2
go.sum
|
@ -16,6 +16,8 @@ github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaW
|
|||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
|
||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/kuangchanglang/graceful v1.0.2 h1:67kR+XSl2iR5pnCIuI2bH3Ke1aT9uL2h7cZIiqRtlj0=
|
||||
github.com/kuangchanglang/graceful v1.0.2/go.mod h1:fQkb+p3PRjvdiAsa65Qv78lm9CsYc4M+yhiuU1rOVtg=
|
||||
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
|
||||
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
|
|
Loading…
Reference in New Issue