# README
This package provides a way to initialize possible errors and handle them with ease.
Installation
The only requirement is the Go Programming Language.
$ go get -u gopkg.in/kataras/go-errors.v0
Docs
New
New
receives a message format and creates a new Error. Message format, which is created with .New, is never changes.
import "gopkg.in/kataras/go-errors.v0"
var errUserAlreadyJoined = errors.New("User with username: %s was already joined in this room!")
Format
Format
is like fmt.Sprintf
but for specific Error, returns a new error with the formatted message.
import "gopkg.in/kataras/go-errors.v0"
var errUserAlreadyJoined = errors.New("User with username: %s was already joined in this room!")
func anything() error {
return errUserAlreadyJoined.Format("myusername")
// will return an error with message =
// User with username: myusername was already joined in this room!
//
}
Append
Append
and AppendErr
adds a message to existing message and returns a new error.
import "gopkg.in/kataras/go-errors.v0"
var errUserAlreadyJoined = errors.New("User with username: %s was already joined in this room!")
func anything() error {
return errUserAlreadyJoined.Append("Please specify other room.").Format("myusername")
// will return an error with message =
// User with username: myusername was already joined in this room!
// Please specify other room.
//
}
import "gopkg.in/kataras/go-errors.v0"
var errUserAlreadyJoined = errors.New("User with username: %s was already joined in this room!")
var errSpecifyOtherRoom = errors.New("Please specify other room.")
func anything() error {
return errUserAlreadyJoined.AppendErr(errSpecifyOtherRoom).Format("myusername")
// will return an error with message =
// User with username: myusername was already joined in this room!
// Please specify other room.
//
}
Use AppendErr
with go standard error type
import (
"gopkg.in/kataras/go-errors.v0"
"fmt"
)
var errUserAlreadyJoined = errors.New("User with username: %s was already joined in this room!")
func anything() error {
err := fmt.Errorf("Please specify other room") // standard golang error
return errUserAlreadyJoined.AppendErr(err).Format("myusername")
// will return an error with message =
// User with username: myusername was already joined in this room!
// Please specify other room.
//
}
go-* packages
Name | Description |
---|---|
go-fs | FileSystem utils and common net/http static files handlers |
go-events | EventEmmiter for Go |
go-websocket | A websocket server and ,optionally, client side lib for Go |
go-ssh | SSH Server, build ssh interfaces, remote commands and remote cli with ease |
go-gzipwriter | Write gzip data to a io.Writer |
go-mailer | E-mail Sender, send rich mails with one call |
rizla | Monitor and live-reload of your Go App |
Q | HTTP2 Web Framework, 100% compatible with net/http |
Iris | The fastest web framework. Built on top of fasthttp |
FAQ
Explore these questions or navigate to the community chat.
Versioning
Current: v0.0.3
People
The author of go-errors is @kataras.
If you're willing to donate, feel free to send any amount through paypal
Contributing
If you are interested in contributing to the go-errors project, please make a PR.
License
This project is licensed under the MIT License.
License can be found here.