https://github.com/andrewlader/go-gently
The Go-Gently service is a Go language package to enable other Go services to gently shutdown when they receive a SIGTERM, SIGINT or SIGQUIT signal.
https://github.com/andrewlader/go-gently
gentle go golang graceful gracefully shutdown sigint sigterm
Last synced: 5 months ago
JSON representation
The Go-Gently service is a Go language package to enable other Go services to gently shutdown when they receive a SIGTERM, SIGINT or SIGQUIT signal.
- Host: GitHub
- URL: https://github.com/andrewlader/go-gently
- Owner: andrewlader
- License: mit
- Created: 2017-02-12T04:00:51.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-09-27T21:12:04.000Z (over 5 years ago)
- Last Synced: 2024-06-20T08:10:15.867Z (almost 2 years ago)
- Topics: gentle, go, golang, graceful, gracefully, shutdown, sigint, sigterm
- Language: Go
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-gently
[](https://goreportcard.com/report/github.com/andrewlader/go-gently)
[](https://travis-ci.org/andrewlader/go-gently)
[](https://codecov.io/gh/andrewlader/go-gently)
[](https://github.com/AndrewLader/go-gently/blob/master/LICENSE)
The Go-Gently service is a Go language package to enable other Go services to gently shutdown when they receive a `SIGTERM`, `SIGINT` or `SIGQUIT` signal.
> "Do not go gentle into that good night"
> -- Dylan Thomas, 1914 - 1953
While **Dylan Thomas** urges us _not_ to go gentle into that good night in his famous poem, we _do_ want our services to do just that. This library makes that possible.
```
██████╗ ██████╗ ██████╗ ███████╗███╗ ██╗████████╗██╗ ██╗ ██╗
██╔════╝ ██╔═══██╗ ██╔════╝ ██╔════╝████╗ ██║╚══██╔══╝██║ ╚██╗ ██╔╝
██║ ███╗██║ ██║█████╗██║ ███╗█████╗ ██╔██╗ ██║ ██║ ██║ ╚████╔╝
██║ ██║██║ ██║╚════╝██║ ██║██╔══╝ ██║╚██╗██║ ██║ ██║ ╚██╔╝
╚██████╔╝╚██████╔╝ ╚██████╔╝███████╗██║ ╚████║ ██║ ███████╗██║
╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝ ╚══════╝╚═╝
```
### Usage
There are two simple steps necessary to use go-gently in a go service or application.
#### Step One
The first step is to implement the `Gently` interface on each of the `struct`s that should be notified to stop gently. The `Gently` interface definition is:
```
// Gently is the interface a struct must implement if it wants to be registered
// to notified as to when to stop gently
type Gently interface {
GetName() string
StopGently(sginal os.Signal)
}
```
#### Step Two
In the `main` func, make the following calls:
**Sample Code**
```
import "github.com/AndrewLader/go-gently"
myStuct := NewMyStruct()
goodNight := gently.New()
goodNight.Register(myStruct)
```
### GoodNight struct
The `GoodNight` struct is used to manage the structs in a Go service that implement the `Gently` interface. The `Register` method is used to register a given struct that implements the `Gently` interface.
```
// Register is used to register a struct that implements the Gently interface
// with the GoodNight struct so it can be notified when to stop gently
func (goodNight *GoodNight) Register(toBeRegistered Gently)
```