2015-10-02 03:24:38 +02:00
|
|
|
---
|
|
|
|
title: Graceful Shutdown
|
|
|
|
menu:
|
|
|
|
main:
|
|
|
|
parent: recipes
|
|
|
|
---
|
2015-06-30 20:51:08 +02:00
|
|
|
|
|
|
|
### With [graceful](https://github.com/tylerb/graceful)
|
|
|
|
|
|
|
|
`server.go`
|
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/labstack/echo"
|
|
|
|
"github.com/tylerb/graceful"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// Setup
|
|
|
|
e := echo.New()
|
|
|
|
e.Get("/", func(c *echo.Context) error {
|
|
|
|
return c.String(http.StatusOK, "Sue sews rose on slow jor crows nose")
|
|
|
|
})
|
|
|
|
|
|
|
|
graceful.ListenAndServe(e.Server(":1323"), 5*time.Second)
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### With [grace](https://github.com/facebookgo/grace)
|
|
|
|
|
|
|
|
`server.go`
|
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/facebookgo/grace/gracehttp"
|
|
|
|
"github.com/labstack/echo"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// Setup
|
|
|
|
e := echo.New()
|
|
|
|
e.Get("/", func(c *echo.Context) error {
|
|
|
|
return c.String(http.StatusOK, "Six sick bricks tick")
|
|
|
|
})
|
|
|
|
|
|
|
|
gracehttp.Serve(e.Server(":1323"))
|
|
|
|
}
|
|
|
|
```
|
2015-06-30 21:10:35 +02:00
|
|
|
|
|
|
|
## Source Code
|
|
|
|
|
|
|
|
[`graceful`](https://github.com/labstack/echo/blob/master/recipes/graceful-shutdown/graceful)
|
|
|
|
|
|
|
|
[`grace`](https://github.com/labstack/echo/blob/master/recipes/graceful-shutdown/grace)
|