Documentation ¶
Overview ¶
Package cleanup provides common helpers for common cleanup patterns on defer
Use the helpers with `defer`. For example use IfNot with `defer`, such that cleanup functions will be executed if `check` is false, no matter if an error has been returned or an panic has occured.
initOK := false defer cleanup.IfNot(&initOK, func() { cleanup }) ... // init structures... initOK = true // notify handler cleanup code must not be executed
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func If ¶
func If(check *bool, cleanup func())
If will run the cleanup function if the bool value is true.
func IfNot ¶
func IfNot(check *bool, cleanup func())
IfNot will run the cleanup function if the bool value is false.
func IfNotPred ¶
func IfNotPred(pred func() bool, cleanup func())
IfNotPred will run the cleanup function if pred returns false.
func IfPred ¶
func IfPred(pred func() bool, cleanup func())
IfPred will run the cleanup function if pred returns true.
func IgnoreError ¶
func IgnoreError(cleanup func() error) func()
IgnoreError silently ignores errors in the cleanup function.
Types ¶
type FailClean ¶
type FailClean struct {
// contains filtered or unexported fields
}
FailClean keeps track of functions to be executed of FailClean did not receive a success signal.
func (*FailClean) Add ¶
func (f *FailClean) Add(fn func())
Add adds another cleanup handler. The last added handler will be run first.