Documentation ¶
Overview ¶
Helpers so generic & useful they "could/should be" language-level features.
The name "builtin" is to align with Go's "builtin = predeclared identifiers", see https://pkg.go.dev/builtin
This package is intended to be imported with . so they can be used in non-qualified way.
Index ¶
- func ErrorIfUnset(isUnset bool, fieldName string) error
- func ErrorWrap(prefix string, err error) error
- func FirstError(errs ...error) error
- func FirstNonEmpty[T comparable](values ...T) T
- func IgnoreErrorIfCanceled(ctx context.Context, err error) error
- func Must[T any](value T, err error) T
- func Pointer[T any](val T) *T
- type Void
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorIfUnset ¶
errors if a field is unset. it is up to the caller to evaluate if the field is unset
func ErrorWrap ¶
helper for wrapping an error with error prefix. if error is nil, nil is returned. Deprecated: this doesn't carry its own weight - just use `fmt.Errorf()`
func FirstError ¶
returns first error, or nil if no errors Deprecated: use `FirstNonEmpty()`
func FirstNonEmpty ¶
func FirstNonEmpty[T comparable](values ...T) T
returns the first non-empty value.
func IgnoreErrorIfCanceled ¶
ignores error in situations where context was canceled and thus errors are to be expected and thus are non-interesting
func Must ¶
for a function that returns two values, you can get the value with `Must(fn())` to convert it to the value, panicking if producing the value caused an error
func Pointer ¶
func Pointer[T any](val T) *T
returns a pointer to the given value.
Go is so silly, we need to do this. AWS has similar helpers: https://pkg.go.dev/github.com/aws/aws-sdk-go/aws#String
Types ¶
type Void ¶
type Void struct{}
empty struct with a semantic name, meaning no information is conveyed. example use cases: - https://pkg.go.dev/context?utm_source=godoc#Context.Done - visitedItems := map[string]Void{}