https://github.com/thombashi/eoe
Provide a simple function to exit the program with an error message on errors in Go.
https://github.com/thombashi/eoe
golang-library
Last synced: 4 months ago
JSON representation
Provide a simple function to exit the program with an error message on errors in Go.
- Host: GitHub
- URL: https://github.com/thombashi/eoe
- Owner: thombashi
- License: mit
- Created: 2024-06-08T06:47:48.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-04T14:31:55.000Z (5 months ago)
- Last Synced: 2025-01-04T15:22:28.275Z (5 months ago)
- Topics: golang-library
- Language: Go
- Homepage: https://pkg.go.dev/github.com/thombashi/eoe
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# eoe
Provide a simple function to exit the program with an error message on errors in Go.
[](https://pkg.go.dev/github.com/thombashi/eoe)
[](https://goreportcard.com/report/github.com/thombashi/eoe)
[](https://github.com/thombashi/eoe/actions/workflows/ci.yaml)
[](https://github.com/thombashi/eoe/actions/workflows/github-code-scanning/codeql)## Installation
```
go get -u github.com/thombashi/eoe
```## Usage
```go
package mainimport (
"github.com/thombashi/eoe"
)func successFunc() error {
return nil
}func errrorFunc() error {
return errors.New("an error occurred")
}func main() {
var err error
logger := slog.Default()
params := eoe.NewParams().WithLogger(logger)// should not exit if the error is nil
err = successFunc()
eoe.ExitOnError(err, params.WithMessage("should not exit"))// should exit if the error is not nil
err = errrorFunc()
eoe.ExitOnError(err, params.WithMessage("should exit with an error message"))
}
```