Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wavesoftware/go-ensure
A simple ensure package for Golang
https://github.com/wavesoftware/go-ensure
Last synced: about 12 hours ago
JSON representation
A simple ensure package for Golang
- Host: GitHub
- URL: https://github.com/wavesoftware/go-ensure
- Owner: wavesoftware
- License: apache-2.0
- Created: 2020-01-25T12:19:57.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-25T14:25:19.000Z (almost 5 years ago)
- Last Synced: 2024-10-19T03:18:17.880Z (about 1 month ago)
- Language: Go
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ensure for Go
A simple ensure package for Golang
## Use case
Writing a Go code makes a lot of repetition, regarding error checking. That's
especially true for end user code like e2e tests when we expect that something
will work. In other cases that's a bug and should code should panic then.## Usage
Instead of writing:
```go
func DeployAllComponents() error {
alpha, err := deployAlpha()
if err != nil {
return errors.WithMessage(err, "unexpected error")
}
beta, err := deployBeta(alpha)
if err != nil {
return errors.WithMessage(err, "unexpected error")
}
_, err := deployGamma(beta)
if err != nil {
return errors.WithMessage(err, "unexpected error")
}
return nil
}// execution isn't simple
err = DeployAllComponents()
if err != nil {
panic(err)
}
```with this PR I can write it like:
```go
func DeployAllComponents() {
alpha, err := deployAlpha()
ensure.NoError(err)
beta, err := deployBeta(alpha)
ensure.NoError(err)
_, err := deployGamma(beta)
ensure.NoError(err)
}// execution is simple
DeployAllComponents()
```Above is much more readable and pleasant to see.