Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/theodesp/go-invariant
A way to provide descriptive errors in development but generic errors in production for go programs.
https://github.com/theodesp/go-invariant
golang invariant
Last synced: about 1 month ago
JSON representation
A way to provide descriptive errors in development but generic errors in production for go programs.
- Host: GitHub
- URL: https://github.com/theodesp/go-invariant
- Owner: theodesp
- License: mit
- Created: 2016-04-26T15:45:10.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-10-09T08:36:10.000Z (about 6 years ago)
- Last Synced: 2024-10-03T07:21:59.182Z (about 2 months ago)
- Topics: golang, invariant
- Language: Go
- Size: 813 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# go-invariant
A way to provide descriptive errors in development but generic errors in production.
Install
=============```bash
go get github.com/theodesp/go-invariant
```
Usage
====It's intended for projects which require a simple invariant check and display
of error messages depending on the current env variablesExamples:
```go
// main.go
package mainimport (
"github.com/theodesp/go-invariant"
"fmt"
)func main() {
res:= invariant.Invariant(1!=1,"")
fmt.Println(res)
}```
and run on the command line
```bash
$ go run main.go
invariant requires an error message argument$ go run main.go -env production
invariant exception in production environment. Please use development flag to see the full error message
``````go
// main.go
package mainimport (
"github.com/theodesp/go-invariant"
"fmt"
)func main() {
res:= invariant.Invariant(1!=1,"You must say %s when talking to Dragons", "your majesty")
fmt.Println(res)
}```
and run on the command line
```bash
$ go run main.go
You must say your majesty when talking to Dragons$ go run main.go -env production
invariant exception in production environment. Please use development flag to see the full error message
```Note: When **env** environment variable or command line switch
is not *production*, the message is required.
If omitted, invariant will throw regardless of the truthness of the condition.
When **env** is *production*, the message will be a generic one so it can be stripped away
By default **env** is assumed to be *development*.