https://github.com/onsi/gocleanup
GoCleanup: kinda like atexit()
https://github.com/onsi/gocleanup
Last synced: 3 months ago
JSON representation
GoCleanup: kinda like atexit()
- Host: GitHub
- URL: https://github.com/onsi/gocleanup
- Owner: onsi
- License: mit
- Created: 2014-03-31T21:06:01.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2014-03-31T21:16:00.000Z (about 12 years ago)
- Last Synced: 2025-03-27T01:11:28.943Z (about 1 year ago)
- Language: Go
- Size: 137 KB
- Stars: 6
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
GoCleanup
=========
It's kinda like atexit()
GoCleanup is a big bag of singleton methods to enable `atexit`-like behavior in Golang. If you don't like singletons... move along ;)
It's simple. You register functions to run on exit with
```go
gocleanup.Register(func() {
//do stuff
})
```
If the running program receives a SIGINT, or SIGTERM cleanup will intercept the signal, run all the registered clean up functions and then exit with status 1.
If you want to exit from within your code, you'll need to call
```go
gocleanup.Exit(statuscode)
```
to ensure the cleanup callbacks are run.
Finally, if you want to manually invoke the cleanup callbacks (without exiting):
```go
gocleanup.Cleanup()
```
this will also unregister any registered cleanup functions.