forked from mirror/gin
Merge branch 'master' into develop
This commit is contained in:
commit
e9531e5c76
21
README.md
21
README.md
|
@ -128,7 +128,7 @@ func main() {
|
||||||
})
|
})
|
||||||
|
|
||||||
// However, this one will match /user/john/ and also /user/john/send
|
// However, this one will match /user/john/ and also /user/john/send
|
||||||
// If no other routers match /user/john, it will redirect to /user/join/
|
// If no other routers match /user/john, it will redirect to /user/john/
|
||||||
router.GET("/user/:name/*action", func(c *gin.Context) {
|
router.GET("/user/:name/*action", func(c *gin.Context) {
|
||||||
name := c.Param("name")
|
name := c.Param("name")
|
||||||
action := c.Param("action")
|
action := c.Param("action")
|
||||||
|
@ -652,3 +652,22 @@ func main() {
|
||||||
s.ListenAndServe()
|
s.ListenAndServe()
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Graceful restart or stop
|
||||||
|
|
||||||
|
Do you want to graceful restart or stop your web server?
|
||||||
|
There be some ways.
|
||||||
|
|
||||||
|
We can using fvbock/endless to replace the default ListenAndServe
|
||||||
|
|
||||||
|
Refer the issue for more details:
|
||||||
|
|
||||||
|
https://github.com/gin-gonic/gin/issues/296
|
||||||
|
|
||||||
|
```go
|
||||||
|
router := gin.Default()
|
||||||
|
router.GET("/", handler)
|
||||||
|
// [...]
|
||||||
|
endless.ListenAndServe(":4242", router)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
|
@ -103,10 +103,10 @@ func (c *Context) IsAborted() bool {
|
||||||
return c.index >= abortIndex
|
return c.index >= abortIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
// Abort stops the system to continue calling the pending handlers in the chain.
|
// Abort prevents pending handlers from being called. Note that this will not stop the current handler.
|
||||||
// Let's say you have an authorization middleware that validates if the request is authorized
|
// Let's say you have an authorization middleware that validates that the current request is authorized. If the
|
||||||
// if the authorization fails (the password does not match). This method (Abort()) should be called
|
// authorization fails (ex: the password does not match), call Abort to ensure the remaining handlers
|
||||||
// in order to stop the execution of the actual handler.
|
// for this request are not called.
|
||||||
func (c *Context) Abort() {
|
func (c *Context) Abort() {
|
||||||
c.index = abortIndex
|
c.index = abortIndex
|
||||||
}
|
}
|
||||||
|
|
6
gin.go
6
gin.go
|
@ -227,7 +227,7 @@ func iterate(path, method string, routes RoutesInfo, root *node) RoutesInfo {
|
||||||
|
|
||||||
// Run attaches the router to a http.Server and starts listening and serving HTTP requests.
|
// Run attaches the router to a http.Server and starts listening and serving HTTP requests.
|
||||||
// It is a shortcut for http.ListenAndServe(addr, router)
|
// It is a shortcut for http.ListenAndServe(addr, router)
|
||||||
// Note: this method will block the calling goroutine undefinitelly unless an error happens.
|
// Note: this method will block the calling goroutine indefinitely unless an error happens.
|
||||||
func (engine *Engine) Run(addr ...string) (err error) {
|
func (engine *Engine) Run(addr ...string) (err error) {
|
||||||
defer func() { debugPrintError(err) }()
|
defer func() { debugPrintError(err) }()
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ func (engine *Engine) Run(addr ...string) (err error) {
|
||||||
|
|
||||||
// RunTLS attaches the router to a http.Server and starts listening and serving HTTPS (secure) requests.
|
// 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)
|
// It is a shortcut for http.ListenAndServeTLS(addr, certFile, keyFile, router)
|
||||||
// Note: this method will block the calling goroutine undefinitelly unless an error happens.
|
// Note: this method will block the calling goroutine indefinitely unless an error happens.
|
||||||
func (engine *Engine) RunTLS(addr string, certFile string, keyFile string) (err error) {
|
func (engine *Engine) RunTLS(addr string, certFile string, keyFile string) (err error) {
|
||||||
debugPrint("Listening and serving HTTPS on %s\n", addr)
|
debugPrint("Listening and serving HTTPS on %s\n", addr)
|
||||||
defer func() { debugPrintError(err) }()
|
defer func() { debugPrintError(err) }()
|
||||||
|
@ -250,7 +250,7 @@ func (engine *Engine) RunTLS(addr string, certFile string, keyFile string) (err
|
||||||
|
|
||||||
// RunUnix attaches the router to a http.Server and starts listening and serving HTTP requests
|
// RunUnix attaches the router to a http.Server and starts listening and serving HTTP requests
|
||||||
// through the specified unix socket (ie. a file).
|
// through the specified unix socket (ie. a file).
|
||||||
// Note: this method will block the calling goroutine undefinitelly unless an error happens.
|
// Note: this method will block the calling goroutine indefinitely unless an error happens.
|
||||||
func (engine *Engine) RunUnix(file string) (err error) {
|
func (engine *Engine) RunUnix(file string) (err error) {
|
||||||
debugPrint("Listening and serving HTTP on unix:/%s", file)
|
debugPrint("Listening and serving HTTP on unix:/%s", file)
|
||||||
defer func() { debugPrintError(err) }()
|
defer func() { debugPrintError(err) }()
|
||||||
|
|
|
@ -12,12 +12,6 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
//TODO
|
|
||||||
// func (engine *Engine) LoadHTMLGlob(pattern string) {
|
|
||||||
// func (engine *Engine) LoadHTMLFiles(files ...string) {
|
|
||||||
// func (engine *Engine) Run(addr string) error {
|
|
||||||
// func (engine *Engine) RunTLS(addr string, cert string, key string) error {
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
SetMode(TestMode)
|
SetMode(TestMode)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue