-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a README file. * Improve documentation on some variable and type.
- Loading branch information
1 parent
e56ed94
commit da57448
Showing
2 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# graceful | ||
|
||
[![Run Tests](https://github.com/gin-contrib/graceful/actions/workflows/go.yml/badge.svg?branch=master)](https://github.com/gin-contrib/graceful/actions/workflows/go.yml) | ||
[![codecov](https://codecov.io/gh/gin-contrib/graceful/branch/master/graph/badge.svg)](https://codecov.io/gh/gin-contrib/graceful) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/gin-contrib/graceful)](https://goreportcard.com/report/github.com/gin-contrib/graceful) | ||
[![GoDoc](https://godoc.org/github.com/gin-contrib/graceful?status.svg)](https://godoc.org/github.com/gin-contrib/graceful) | ||
[![Join the chat at https://gitter.im/gin-gonic/gin](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/gin-gonic/gin) | ||
|
||
Gin wrapper to enable graceful termination when shutting down a process | ||
|
||
## Example | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/gin-contrib/graceful" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func main() { | ||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) | ||
defer stop() | ||
|
||
router, err := graceful.Default() | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer router.Close() | ||
|
||
router.GET("/", func(c *gin.Context) { | ||
c.String(http.StatusOK, "Welcome Gin Server") | ||
}) | ||
|
||
if err := router.RunWithContext(ctx); err != nil && err != context.Canceled { | ||
panic(err) | ||
} | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters