https://github.com/alvarolm/cleanup
defered utility functions
https://github.com/alvarolm/cleanup
Last synced: 21 days ago
JSON representation
defered utility functions
- Host: GitHub
- URL: https://github.com/alvarolm/cleanup
- Owner: alvarolm
- License: mit
- Created: 2020-01-14T23:58:26.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-05-17T03:48:14.000Z (about 1 year ago)
- Last Synced: 2025-05-12T19:15:45.533Z (21 days ago)
- Language: Go
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cleanup
[](https://godoc.org/github.com/alvarolm/cleanup)
[](https://goreportcard.com/report/github.com/alvarolm/cleanup)[](https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=alvarofleivam%40gmail%2ecom&lc=AL&item_name=Donation%20%5b%20for%20a%20bus%20ticket%2c%20coffe%20anything%20you%20can%20I%27m%20happy%20thanks%20%21%20%3a%29%20%5d&item_number=donation&button_subtype=services¤cy_code=USD&bn=PP%2dBuyNowBF%3abtn_buynowCC_LG%2egif%3aNonHosted)
cleans up for you !
example:
```go
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
}
```