Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iq-tech/go-utils
This repository contains utility functions that do not make sense in other packages.
https://github.com/iq-tech/go-utils
Last synced: about 2 months ago
JSON representation
This repository contains utility functions that do not make sense in other packages.
- Host: GitHub
- URL: https://github.com/iq-tech/go-utils
- Owner: IQ-tech
- Created: 2021-12-09T16:54:23.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-09T17:10:12.000Z (about 3 years ago)
- Last Synced: 2024-06-21T06:20:43.912Z (6 months ago)
- Language: Go
- Homepage:
- Size: 1000 Bytes
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Installation
```terminal
go get github.com/IQ-tech/go-utils
```## Executing code before process exits
`AtInterruption` receives a function that will be called once before the process exits.
`AtInterruption` can be called many times with different functions and each function will be
called once.```go
utils.AtInterruption(func() {
log.Printf("Closing DB Connection.")
db.Close()log.Printf("Shutting down New Relic application.")
nrl.Shutdown(5 * time.Second)
})
```## Logging and terminating the process on error
`EndAsErr` will log the error message and terminate the process if `err` is not `nil`
```go
func main() {
di := setup.Start()
err := server.Start(di)
utils.EndAsErr(err, "Could not start the server.", di.Log.InfoWriter(), di.Log.ErrorWriter())
}```