https://github.com/go-playground/kms
:hocho: Is a library that aids in graceful shutdown of a process/application
https://github.com/go-playground/kms
graceful-shutdown
Last synced: about 1 month ago
JSON representation
:hocho: Is a library that aids in graceful shutdown of a process/application
- Host: GitHub
- URL: https://github.com/go-playground/kms
- Owner: go-playground
- License: mit
- Created: 2016-10-27T19:47:12.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-27T19:18:49.000Z (over 8 years ago)
- Last Synced: 2025-08-14T10:16:28.806Z (about 2 months ago)
- Topics: graceful-shutdown
- Language: Go
- Size: 18.6 KB
- Stars: 49
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## KMS

[](https://semaphoreci.com/joeybloggs/kms)
[](https://coveralls.io/github/go-playground/kms)
[](https://goreportcard.com/report/github.com/go-playground/kms)
[](https://godoc.org/github.com/go-playground/kms)
KMS(Killing Me Softly) is a library that aids in graceful shutdown of a process/application.
Why does this even exist? Aren't there other graceful shutdown librarys?
-------------
Sure there are other libraries, but they are focused on handling graceful shutdown a specific portion of
code such as graceful shutdown of an http server, but this library allows you to glue together multiple
unrelated(or related) services running within the same process/application.Doesn't Go 1.8 handle graceful shutdown?
------------
Yes and No, it does not yet handle Hijacked connections, like WebSockets, see:
- https://github.com/golang/go/issues/4674#issuecomment-257549871
- https://github.com/golang/go/issues/17721#issuecomment-257572027but this package does; furthermore this package isn't just for graceful http shutdown but graceful shutdown of anything and everything.
When Go 1.8 comes out I will transparently make changes to let the std lib handle idle connections as
it has lower level access to them, but continue to handle Hijacked connections.Installation
-----------Use go get
```shell
go get -u github.com/go-playground/kms
```Built In
--------
There are a few built in graceful shutdown helpers using the kms package for:
- TCP
- Unix Sockets
- HTTP(S) graceful shutdown.Examples
-------
[see here](https://github.com/go-playground/kms/tree/master/examples) for more```go
package mainimport (
"net/http"
"time""github.com/go-playground/kms"
"github.com/go-playground/kms/kmsnet/kmshttp"
)func main() {
// listen for shutdown signal(s) with timeout, non-blocking
kms.ListenTimeout(false, time.Minute*3)http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Home"))
})kmshttp.ListenAndServe(":3007", nil)
}
```Package Versioning
----------
I'm jumping on the vendoring bandwagon, you should vendor this package as I will not
be creating different version with gopkg.in like allot of my other libraries.Why? because my time is spread pretty thin maintaining all of the libraries I have + LIFE,
it is so freeing not to worry about it and will help me keep pouring out bigger and better
things for you the community.I am open versioning with gopkg.in should anyone request it, but this should be stable going forward.
Licenses
--------
- [MIT License](https://raw.githubusercontent.com/go-playground/kms/master/LICENSE) (MIT), Copyright (c) 2016 Dean Karn