builtin

package
v0.0.0-...-a5f7211 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 2 Imported by: 3

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorIfUnset

func ErrorIfUnset(isUnset bool, fieldName string) error

errors if a field is unset. it is up to the caller to evaluate if the field is unset

func ErrorWrap

func ErrorWrap(prefix string, err error) error

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

func FirstError(errs ...error) error

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

func IgnoreErrorIfCanceled(ctx context.Context, err error) error

ignores error in situations where context was canceled and thus errors are to be expected and thus are non-interesting

func Must

func Must[T any](value T, err error) T

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{}

Jump to

Keyboard shortcuts

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