Introduction
As I work on various Go projects, I often find myself creating utility functions, extending existing packages, or developing packages to solve specific problems. Moving from one project to another, I usually have to copy or rewrite these solutions. So I created this repository to have all these utilities and packages in one place. Hopefully, you'll find them useful as well.
These packages aim to enhance the functionality of the standard library and other popular packages. They are intended to be used together with other packages rather than replacing them. The APIs are designed based on my experience working with Go, focusing on simplicity and ease of use. I will try to follow best practices in Go, but not always. I also tend to choose a more performance implementation if possible.
ezpkg.io/errorz
Package errorz provides functions for dealing with errors, with stacktrace, validation, and multi-errors.
Examples
Must
data := errorz.Must(os.ReadFile(path))
fmt.Printf("%s", data)
errorz.MustZ(os.WriteFile(path, data, 0644))
Stacktrace
err := fmt.Errorf("foo")
zErr := errorz.Wrapf(err, "bar/%v", "one")
fmt.Printf("%v\n", zErr)
// bar/one: foo
fmt.Printf("%+v\n", zErr)
// bar/one: foo
// ezpkg.io/errorz_test.TestError.func1
// /Users/i/ws/ezpkg/ezpkg/errorz/errorz_test.go:12
// testing.tRunner
// /usr/local/go/src/testing/testing.go:7890
fmt.Printf("%#v\n", zErr)
// bar/one: foo
// ezpkg.io/errorz_test/errorz_test.go:12 · TestError.func1
// testing/testing.go:7890 · tRunner
No stacktrace
zErr := errorz.NoStack().New("no stack")
fmt.Printf("%+v", zErr)
Multi-errors
var err error
errorz.AppendTo(&err, fmt.Errorf("foo"))
errorz.AppendTo(&err, nil)
fmt.Printf("%+v", err)
var err2 error
err2 = errorz.Append(err2, err)
fmt.Printf("%+v", err2)