Get an easier and faster way to code http error handling in your web app. Largely used on americanas-go/ignite rest app module.
go get -u github.com/americanas-go/errors
import (
"log"
"github.com/americanas-go/errors"
)
func main() {
err := errors.AlreadyExistsf("order id %s", "123")
log.Fatalf(err.Error())
// output: 2021/06/07 15:15:08 order id 123 already exists
}
package main
import (
"log"
"github.com/americanas-go/errors"
)
func main() {
err := errors.BadRequestf("order id is required")
switch {
case errors.IsAlreadyExists(err):
log.Fatalf(err.Error())
case errors.IsForbidden(err):
log.Fatalf(err.Error())
case errors.IsBadRequest(err):
log.Fatalf(err.Error())
// output: 2021/06/07 15:40:06 order id is required
default:
//...
}
}
Every help is always welcome. Feel free do throw us a pull request, we'll do our best to check it out as soon as possible. But before that, let us establish some guidelines:
- This is an open source project so please do not add any proprietary code or infringe any copyright of any sort.
- Avoid unnecessary dependencies or messing up go.mod file.
- Be aware of golang coding style. Use a lint to help you out.
- Add tests to cover your contribution.
- Add godoc to your code.
- Use meaningful messages to your commits.
- Use pull requests.
- At last, but also important, be kind and polite with the community.
Any submitted issue which disrespect one or more guidelines above, will be discarded and closed.
Released under the MIT License.