You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
trash deal with logging, sending and stacking errors.
Currently supporting json and xml format.
And also implementing the standard error interface.
Example
Creating a new err.
import"log"import"errors"funcmain() {
// Takes a logger and data format (json, xml)t:=trash.New(logger, "json")
if1!=2 {
// Default Err// Arguments (Error Type, Error Message) -> (string, string or error)t.NewErr(trash.GenericErr, errors.New("example err")).Send(rw).Log()
// HTTP Errt.NewErr(trash.GenericErr, "useless error").SendHTTP(rw, 404).LogHTTP(req)
// Standalone inline HTTP error declaringtrash.NewJSONErr(trash.InvalidDataErr, "1 not equal 2 ...").LogHTTP(req).SendHTTP(rw, 406)
}
}
You can also create a dump. Which is an error stack you want to backup.
A dump need a io.Writer to save the errors stack.
funcmain() {
t:=trash.New(logger, "json")
t2:=trash.New(logger, "xml")
// The dump will write all errors from the provided trash in a log file or any io.Writer.trash.NewDump(file, t, t2)
if1!=2 {
t.NewErr(trash.InvalidDataErr, "1 not equal 2")
}
}
TODO
DOC
More Testing
Debugging
Optimisation
Contributing
Fork it
Create your feature branch (git checkout -b my-new-feature)
Write Tests!
Commit your changes (git commit -am 'Add some feature')
Push to the branch (git push origin my-new-feature)