pkg

module
v0.0.46-2e8eb6d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2025 License: Apache-2.0

README

pkg

Coverage Go Report Card Go Reference

A generic template I use when making new go projects, and a collection of small, helpful packages that I don't want to rewrite anymore.

errors

Prefix the calling functions name to errors for simpler, smaller traces. This package tries to split the difference between github.com/pkg/errors and Go stdlib errors, with first class support for log/slog.

A full stack trace makes it harder to parse errors at a glance, especially if they are wrapped multiple times. But relying only on the stdlib's fmt.Errorf will have you grepping through the codebase instead, which is not ideal.

This package encourages you to Wrap errors as they bubble up through the call stack. Wrapping multiple times won't punish you with stuttered stack traces. They will only improve the error with more function names.

And the resulting error will be self-explanatory... Or more realistically as explanatory your package and function names. https://go.dev/doc/effective_go#names is still great advice.

The error will also include the file:line info from the very first error in the chain.

WrapAttr enables structured errors, allowing metadata to be easily included in logs. log/slog support is built in. Slogging an error will include the file:line info from the start of an error chain and any metadata from WrapAttr calls.

errors/attr_test.go includes example output.

ptr

ptr.To and ptr.From have been recreated in every Go codebase dealing with openapi or protobuf code generation, even before generics. They should probably be in the stdlib.

Directories

Path Synopsis
cmd
changeme command
Package main is an example entrypoint stub.
Package main is an example entrypoint stub.
Package errors prefixes the calling functions name to errors for simpler, smaller traces.
Package errors prefixes the calling functions name to errors for simpler, smaller traces.
Package ioutil extends the stdlib ioutil
Package ioutil extends the stdlib ioutil
Package ptr provides utility functions for working with pointers.
Package ptr provides utility functions for working with pointers.
Package retry provides retryable context-aware functions for code that needs to be robust against transient failures.
Package retry provides retryable context-aware functions for code that needs to be robust against transient failures.
Package set provides a bog standard set implementation for Go, just a wrapper around a map[T comparable]struct{} Most set methods mutate the set and return it to facilitate method chaining.
Package set provides a bog standard set implementation for Go, just a wrapper around a map[T comparable]struct{} Most set methods mutate the set and return it to facilitate method chaining.
Package test provides helper functions for testing.
Package test provides helper functions for testing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL