You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This supports loggers who do return an error from their Error and Warn functions like seelog
Example
go get gopkg.in/vrecan/death.v2
Use The Library
package main
import (
DEATH "github.com/vrecan/death"
SYS "syscall"
)
funcmain() {
death:=DEATH.NewDeath(SYS.SIGINT, SYS.SIGTERM) //pass the signals you want to end your application//when you want to block for shutdown signalsdeath.WaitForDeath() // this will finish when a signal of your type is sent to your application
}
Close Other Objects On Shutdown
One simple feature of death is that it can also close other objects when shutdown starts
package main
import (
DEATH "github.com/vrecan/death"
SYS "syscall""io"
)
funcmain() {
death:=DEATH.NewDeath(SYS.SIGINT, SYS.SIGTERM) //pass the signals you want to end your applicationobjects:=make([]io.Closer, 0)
objects=append(objects, &NewType{}) // this will work as long as the type implements a Close method//when you want to block for shutdown signalsdeath.WaitForDeath(objects...) // this will finish when a signal of your type is sent to your application
}
typeNewTypestruct {
}
func (c*NewType) Close() error {
returnnil
}
Or close using an anonymous function
package main
import (
DEATH "github.com/vrecan/death"
SYS "syscall"
)
funcmain() {
death:=DEATH.NewDeath(SYS.SIGINT, SYS.SIGTERM) //pass the signals you want to end your application//when you want to block for shutdown signalsdeath.WaitForDeathWithFunc(func(){
//do whatever you want on death
})
}