Skip to content

alvarolm/cleanup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cleanup

Godoc Reference Go Report

donate

cleans up for you !

example:

func ProcessQuery()  (err error) {
	cleaner := NewCleaner(&err)
	defer cleaner.Clean()

	...

	// (some logic that needs to be executed only if ProcessQuery returns an error)
	cleaner.OnError(func(e err) {
		if e == ErrTxFailed {
			transaction.Rollback()
		} else {
			log.Errorf("failed request ID: %s", reqID)
		}
	})

	... 

	// (some logic that needs to be executed only if ProcessQuery returns no error)
	cleaner.OnNil(func() { log.Infof("request ID: %s succeded", reqID)

	...

	// (some logic that needs to be executed always no matter what)
	cleaner.Always(func() { wipebytes(thisByteSliceShouldBeZeroedAlways) })

	...

	return
}