var ( // runtime sets these for us Gosched func() Goid func() uint64 Throw func(string) )
func Add(h Hook)
Add adds a new exit hook.
func Run(code int)
Run runs the exit hooks.
If an exit hook panics, Run will throw with the panic on the stack. If an exit hook invokes exit in the same goroutine, the goroutine will throw. If an exit hook invokes exit in another goroutine, that exit will block.
A Hook is a function to be run at program termination (when someone invokes os.Exit, or when main.main returns). Hooks are run in reverse order of registration: the first hook added is the last one run.
type Hook struct { F func() // func to run RunOnFailure bool // whether to run on non-zero exit code }