README
¶
Death 
Simple library to make it easier to manage the death of your application.
Get The Library
go get github.com/vrecan/death
Use The Library
package main
import (
DEATH "github.com/vrecan/death"
SYS "syscall"
)
func main() {
death := DEATH.NewDeath(SYS.SIGINT, SYS.SIGTERM) //pass the signals you want to end your application
//when you want to block for shutdown signals
death.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"
)
func main() {
death := DEATH.NewDeath(SYS.SIGINT, SYS.SIGTERM) //pass the signals you want to end your application
objects := 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 signals
death.WaitForDeath(objects...) // this will finish when a signal of your type is sent to your application
}
type NewType struct {
}
func (c *NewType) Close() error {
return nil
}
Or close using an anonymous function
package main
import (
DEATH "github.com/vrecan/death"
SYS "syscall"
)
func main() {
death := DEATH.NewDeath(SYS.SIGINT, SYS.SIGTERM) //pass the signals you want to end your application
//when you want to block for shutdown signals
death.WaitForDeathWithFunc(func(){
//do whatever you want on death
})
}
Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Death ¶
type Death struct {
// contains filtered or unexported fields
}
Death manages the death of your application.
func (*Death) FallOnSword ¶
func (d *Death) FallOnSword()
FallOnSword manually initiates the death process.
func (*Death) SetTimeout ¶
SetTimeout Overrides the time death is willing to wait for a objects to be closed.
func (*Death) WaitForDeath ¶
WaitForDeath wait for signal and then kill all items that need to die.
func (*Death) WaitForDeathWithFunc ¶
func (d *Death) WaitForDeathWithFunc(f func())
WaitForDeathWithFunc allows you to have a single function get called when it's time to kill your application.
Click to show internal directories.
Click to hide internal directories.