Documentation
¶
Overview ¶
Package kms (Killing Me Softly) is a library that aids in graceful shutdown of a process/application.
Example:
package main import ( "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) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllowSignalHardShutdown ¶
func AllowSignalHardShutdown(allow bool)
AllowSignalHardShutdown allows you to set whether the application should allow hard shutdown of the application if two signals for shutdown should cause a hard shutdown. eg. user running application from the command line types CTRL + C, the application begins to shut down gracefully, if the user types another CTRL + C should the application shut down hard?
Default: true
func Done ¶
func Done()
Done signifies that your application is done performing an operation. it is different from the chained version as it does not need to be connected the the wait object.
func Listen ¶
func Listen(block bool)
Listen sets up signals to listen for interrupt or kill signals in an attempt to wait for all operations to complete before letting the process die.
func ListenTimeout ¶
ListenTimeout sets up signals to listen for interrupt or kill signals in an attempt to wait for all operations to complete before letting the process die.
the wait duration is how long to wait before forcefully shutting everything down.
func SetSignalFn ¶
func SetSignalFn(fn SignalFn)
SetSignalFn allows registering of a custom signal function if you wish to listen for different signals, or even your own custom logic not related to signals. By default this function listens for syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP
func ShutdownComplete ¶
func ShutdownComplete() <-chan struct{}
ShutdownComplete returns a notification channel for the package which will be closed/notified once termination is imminent.
func ShutdownInitiated ¶
func ShutdownInitiated() <-chan struct{}
ShutdownInitiated returns a notification channel for the package which will be closed/notified once a termination signal is received.
useful when other code, such as a custom TCP connection listener needs to be notified to stop listening for new connections.
Types ¶
type KillingMeSoftly ¶
type KillingMeSoftly interface {
Done()
}
KillingMeSoftly interface contains all functions needed for operation and method chaining
func Wait ¶
func Wait() KillingMeSoftly
Wait signifies that your application is busy performing an operation.
best to chain using defer kms.Wait().Done()