Documentation ¶
Overview ¶
Package core provides fundamental helpers for darvaza.org projects
Index ¶
- Constants
- Variables
- func AddrFromNetIP(addr net.Addr) (netip.Addr, bool)
- func AddrPort(v any) (netip.AddrPort, bool)
- func As[T, V any](v T) (V, bool)
- func AsError[T any](v T) error
- func AsErrors[T any](vv []T) []error
- func AsFn[T, V any](fn func(T) (V, bool), v T) (V, bool)
- func Catch(fn func() error) error
- func CheckIsTemporary(err error) (is, known bool)
- func CheckIsTimeout(err error) (is, known bool)
- func Coalesce[T any](opts ...T) T
- func CoalesceError(errs ...error) error
- func GetIPAddresses(ifaces ...string) ([]netip.Addr, error)
- func GetInterfacesNames(except ...string) ([]string, error)
- func GetNetIPAddresses(ifaces ...string) ([]net.IP, error)
- func GetStringIPAddresses(ifaces ...string) ([]string, error)
- func IIf[T any](cond bool, yes, no T) T
- func IsError(err error, errs ...error) bool
- func IsErrorFn(check func(error) bool, errs ...error) bool
- func IsErrorFn2(check func(error) (bool, bool), errs ...error) (is bool, known bool)
- func IsTemporary(err error) bool
- func IsTimeout(err error) bool
- func IsZero(vi any) bool
- func JoinHostPort(host, port string) (string, error)
- func Keys[K comparable, T any](m map[K]T) []K
- func ListContains[T comparable](l *list.List, val T) bool
- func ListContainsFn[T any](l *list.List, val T, eq func(T, T) bool) bool
- func ListCopy[T any](src *list.List) *list.List
- func ListCopyFn[T any](src *list.List, fn func(v T) (T, bool)) *list.List
- func ListForEach[T any](l *list.List, fn func(v T) bool)
- func ListForEachBackward[T any](l *list.List, fn func(v T) bool)
- func ListForEachBackwardElement(l *list.List, fn func(*list.Element) bool)
- func ListForEachElement(l *list.List, fn func(*list.Element) bool)
- func MakeHostPort(hostPort string, defaultPort uint16) (string, error)
- func MapAllListContains[K comparable, T comparable](m map[K]*list.List, v T) bool
- func MapAllListContainsFn[K comparable, T any](m map[K]*list.List, match func(v T) bool) bool
- func MapAllListForEach[K comparable, T any](m map[K]*list.List, fn func(v T) bool)
- func MapAllListForEachElement[K comparable](m map[K]*list.List, fn func(*list.Element) bool)
- func MapContains[K comparable](m map[K]any, key K) bool
- func MapListAppend[K comparable, T any](m map[K]*list.List, key K, v T)
- func MapListAppendUnique[K comparable, T comparable](m map[K]*list.List, key K, v T)
- func MapListAppendUniqueFn[K comparable, T any](m map[K]*list.List, key K, v T, eq func(T, T) bool)
- func MapListContains[K comparable, T comparable](m map[K]*list.List, key K, v T) bool
- func MapListContainsFn[K comparable, T any](m map[K]*list.List, key K, v T, eq func(T, T) bool) bool
- func MapListCopy[T comparable](src map[T]*list.List) map[T]*list.List
- func MapListCopyFn[K comparable, V any](src map[K]*list.List, fn func(v V) (V, bool)) map[K]*list.List
- func MapListForEach[K comparable, T any](m map[K]*list.List, key K, fn func(v T) bool)
- func MapListForEachElement[K comparable](m map[K]*list.List, key K, fn func(el *list.Element) bool)
- func MapListInsert[K comparable, T any](m map[K]*list.List, key K, v T)
- func MapListInsertUnique[K comparable, T comparable](m map[K]*list.List, key K, v T)
- func MapListInsertUniqueFn[K comparable, T any](m map[K]*list.List, key K, v T, eq func(va, vb T) bool)
- func MapValue[K comparable, V any](m map[K]V, key K, def V) (V, bool)
- func NewTemporaryError(err error) error
- func NewTimeoutError(err error) error
- func Panic(payload any)
- func PanicWrap(err error, note string)
- func PanicWrapf(err error, format string, args ...any)
- func Panicf(format string, args ...any)
- func ParseAddr(s string) (addr netip.Addr, err error)
- func ParseNetIP(s string) (ip net.IP, err error)
- func QuietWrap(err error, format string, args ...any) error
- func SliceAs[T, V any](vv []T) []V
- func SliceAsFn[T, V any](fn func(T) (V, bool), vv []T) []V
- func SliceContains[T comparable](a []T, v T) bool
- func SliceContainsFn[T any](a []T, v T, eq func(T, T) bool) bool
- func SliceCopy[T any](s []T) []T
- func SliceCopyFn[T any](s []T, fn func(partial []T, before T) (after T, include bool)) []T
- func SliceEqual[T comparable](a, b []T) bool
- func SliceEqualFn[T any](a, b []T, eq func(va, vb T) bool) bool
- func SliceMap[T1 any, T2 any](a []T1, fn func(partial []T2, v T1) (newEntries []T2)) []T2
- func SliceMinus[T comparable](a []T, b []T) []T
- func SliceMinusFn[T any](a, b []T, eq func(T, T) bool) []T
- func SliceRandom[T any](a []T) (T, bool)
- func SliceReplaceFn[T any](s []T, fn func(partial []T, before T) (after T, replace bool)) []T
- func SliceReverse[T any](x []T)
- func SliceReversed[T any](a []T) []T
- func SliceReversedFn[T any](a []T, fn func(partial []T, before T) (after T, include bool)) []T
- func SliceSort[T any](x []T, cmp func(a, b T) int)
- func SliceSortFn[T any](x []T, less func(a, b T) bool)
- func SliceSortOrdered[T Ordered](x []T)
- func SliceUnique[T comparable](a []T) []T
- func SliceUniqueFn[T any](a []T, eq func(T, T) bool) []T
- func SliceUniquify[T comparable](ptr *[]T) []T
- func SliceUniquifyFn[T any](ptr *[]T, eq func(T, T) bool) []T
- func SortedKeys[K Ordered, T any](m map[K]T) []K
- func SplitAddrPort(addrPort string) (addr netip.Addr, port uint16, err error)
- func SplitHostPort(hostPort string) (host, port string, err error)
- func Unwrap(err error) []error
- func Wrap(err error, msg string) error
- func Wrapf(err error, format string, args ...any) error
- func Zero[T any](_ *T) T
- type Bool
- type CallStacker
- type Catcher
- type Complex
- type CompoundError
- func (w *CompoundError) Append(err error, note string, args ...any)
- func (w *CompoundError) AppendError(errs ...error)
- func (w *CompoundError) AsError() error
- func (w *CompoundError) Error() string
- func (w *CompoundError) Errors() []error
- func (w *CompoundError) Ok() bool
- func (w *CompoundError) Unwrap() []error
- type ContextKey
- type ErrGroup
- func (eg *ErrGroup) Cancel(cause error) bool
- func (eg *ErrGroup) Cancelled() <-chan struct{}
- func (eg *ErrGroup) Context() context.Context
- func (eg *ErrGroup) Done() <-chan struct{}
- func (eg *ErrGroup) Err() error
- func (eg *ErrGroup) Go(run func(context.Context) error, shutdown func() error)
- func (eg *ErrGroup) GoCatch(run func(context.Context) error, catch func(context.Context, error) error)
- func (eg *ErrGroup) IsCancelled() bool
- func (eg *ErrGroup) OnError(fn func(error))
- func (eg *ErrGroup) SetDefaults()
- func (eg *ErrGroup) Wait() error
- type Errors
- type Float
- type Frame
- type Integer
- type Ordered
- type PanicError
- type Recovered
- type Signed
- type SpinLock
- type Stack
- type String
- type TemporaryError
- type Unsigned
- type Unwrappable
- type WaitGroup
- type WrappedError
Constants ¶
const (
// MaxDepth is the maximum depth we will go in the stack.
MaxDepth = 32
)
Variables ¶
var ( // ErrNotImplemented indicates something hasn't been implemented yet ErrNotImplemented = errors.New("not implemented") // ErrTODO is like ErrNotImplemented but used especially to // indicate something needs to be implemented ErrTODO = Wrap(ErrNotImplemented, "TODO") // ErrExists indicates something already exists ErrExists = errors.New("already exists") // ErrNotExists indicates something doesn't exist ErrNotExists = errors.New("does not exist") // ErrInvalid indicates an argument isn't valid ErrInvalid = errors.New("invalid argument") // ErrUnknown indicates something isn't recognized ErrUnknown = errors.New("unknown") // ErrNilReceiver indicates a method was called over a nil instance ErrNilReceiver = errors.New("nil receiver") )
Functions ¶
func AddrFromNetIP ¶
AddrFromNetIP attempts to convert a net.Addr into a netip.Addr
func AsError ¶ added in v0.14.8
AsError attempts to convert a value to an error, checking different interfaces.
* AsError() error * Error() string * OK() bool * IsZero() bool
func AsErrors ¶ added in v0.14.8
AsErrors uses AsError to return the subset of the elements that are errors.
func Catch ¶ added in v0.14.10
Catch uses a Catcher to safely call a function and return the organic error or the Recovered PanicError.
func CheckIsTemporary ¶ added in v0.13.2
CheckIsTemporary tests an error for Temporary(), IsTemporary(), Timeout() and IsTimeout() without unwrapping.
func CheckIsTimeout ¶ added in v0.13.2
CheckIsTimeout tests an error for Timeout() and IsTimeout() without unwrapping.
func CoalesceError ¶ added in v0.9.5
CoalesceError returns the first non-nil error argument. error isn't compatible with Coalesce's comparable generic type.
func GetIPAddresses ¶
GetIPAddresses returns a list of netip.Addr bound to the given interfaces or all if none are given
func GetInterfacesNames ¶
GetInterfacesNames returns the list of interfaces, considering an optional exclusion list
func GetNetIPAddresses ¶
GetNetIPAddresses returns a list of net.IP addresses bound to the given interfaces or all if none are given
func GetStringIPAddresses ¶
GetStringIPAddresses returns a list of text IP addresses bound to the given interfaces or all if none are given
func IsError ¶ added in v0.13.0
IsError recursively check if the given error is in in the given list, or just non-nil if no options to check are given.
func IsErrorFn ¶ added in v0.13.0
IsErrorFn recursively checks if any of the given errors satisfies the specified check function.
revive:disable:cognitive-complexity
func IsErrorFn2 ¶ added in v0.13.0
IsErrorFn2 recursively checks if any of the given errors gets a certain answer from the check function. As opposed to IsErrorFn, IsErrorFn2 will stop when it has certainty of a false result.
revive:disable:cognitive-complexity
func IsTemporary ¶ added in v0.13.2
IsTemporary tests an error for Temporary(), IsTemporary(), Timeout() and IsTimeout() recursively.
func IsTimeout ¶ added in v0.13.2
IsTimeout tests an error for Timeout() and IsTimeout() recursively.
func IsZero ¶ added in v0.9.8
IsZero checks if a non-zero value has been set either by using the `IsZero() bool“ interface or reflection. nil and (*T)(nil) are considered to be zero.
func JoinHostPort ¶ added in v0.14.3
JoinHostPort is like the standard net.JoinHostPort, but it validates the host name and port, and returns it portless if the port argument is empty.
func Keys ¶ added in v0.13.5
func Keys[K comparable, T any](m map[K]T) []K
Keys returns the list of keys of a map
func ListContains ¶
func ListContains[T comparable](l *list.List, val T) bool
ListContains checks if a container/list contains an element
func ListContainsFn ¶
ListContainsFn checks if a container/list contains an element that satisfies a given function
func ListCopyFn ¶ added in v0.14.9
ListCopyFn makes a copy of a list using the given helper
func ListForEach ¶
ListForEach calls a function for each value until told to stop
func ListForEachBackward ¶
ListForEachBackward calls a function for each value until told to stop
func ListForEachBackwardElement ¶
ListForEachBackwardElement calls a function for each element until told to stop
func ListForEachElement ¶
ListForEachElement calls a function for each element until told to stop
func MakeHostPort ¶ added in v0.14.3
MakeHostPort produces a validated host:port from an input string optionally using the given default port when the string doesn't specify one. port 0 on the string input isn't considered valid.
func MapAllListContains ¶
func MapAllListContains[K comparable, T comparable](m map[K]*list.List, v T) bool
MapAllListContains check if a value exists on any entry of the map
func MapAllListContainsFn ¶
MapAllListContainsFn check if a value exists on any entry of the map using a match function
func MapAllListForEach ¶
func MapAllListForEach[K comparable, T any](m map[K]*list.List, fn func(v T) bool)
MapAllListForEach calls a function for each value on all map entries until told to stop
func MapAllListForEachElement ¶
MapAllListForEachElement calls a function for each element on all map entries until told to stop
func MapContains ¶
func MapContains[K comparable](m map[K]any, key K) bool
MapContains tells if a given map contains a key. this helper is intended for switch/case conditions
func MapListAppend ¶
func MapListAppend[K comparable, T any](m map[K]*list.List, key K, v T)
MapListAppend adds a value at the end of the list of a map entry
func MapListAppendUnique ¶
func MapListAppendUnique[K comparable, T comparable](m map[K]*list.List, key K, v T)
MapListAppendUnique adds a value at the end of the list of a map entry if it's not already there
func MapListAppendUniqueFn ¶
func MapListAppendUniqueFn[K comparable, T any](m map[K]*list.List, key K, v T, eq func(T, T) bool)
MapListAppendUniqueFn adds a value at the end of the list of a map entry if it's not already there using a function to compare values
func MapListContains ¶
func MapListContains[K comparable, T comparable](m map[K]*list.List, key K, v T) bool
MapListContains checks if the list.List on a map contains an element
func MapListContainsFn ¶
func MapListContainsFn[K comparable, T any](m map[K]*list.List, key K, v T, eq func(T, T) bool) bool
MapListContainsFn checks if the list.List on a map contains an element using a match functions
func MapListCopy ¶ added in v0.14.9
func MapListCopy[T comparable](src map[T]*list.List) map[T]*list.List
MapListCopy duplicates a map containing a list.List
func MapListCopyFn ¶ added in v0.14.9
func MapListCopyFn[K comparable, V any](src map[K]*list.List, fn func(v V) (V, bool)) map[K]*list.List
MapListCopyFn duplicates a map containing a list.List but allows the element's values to be cloned by a helper function
func MapListForEach ¶
func MapListForEach[K comparable, T any](m map[K]*list.List, key K, fn func(v T) bool)
MapListForEach calls a function for each value on a map entry until told to stop
func MapListForEachElement ¶
MapListForEachElement calls a function for each element on a map entry until told to stop
func MapListInsert ¶
func MapListInsert[K comparable, T any](m map[K]*list.List, key K, v T)
MapListInsert adds a value at the front of the list of a map entry
func MapListInsertUnique ¶
func MapListInsertUnique[K comparable, T comparable](m map[K]*list.List, key K, v T)
MapListInsertUnique adds a value at the front of the list of a map entry if it's not already there
func MapListInsertUniqueFn ¶
func MapListInsertUniqueFn[K comparable, T any](m map[K]*list.List, key K, v T, eq func(va, vb T) bool)
MapListInsertUniqueFn adds a value at the front of the list of a map entry if it's not already there using a function to compare values
func MapValue ¶ added in v0.14.9
func MapValue[K comparable, V any](m map[K]V, key K, def V) (V, bool)
MapValue returns a value of an entry or a default if not found
func NewTemporaryError ¶ added in v0.13.2
NewTemporaryError returns an error that returns false to IsTimeout() and true to IsTemporary()
func NewTimeoutError ¶ added in v0.13.2
NewTimeoutError returns an error that returns true to IsTimeout() and IsTemporary()
func PanicWrapf ¶
PanicWrapf emits a PanicError wrapping an annotated error using a formatting string.
func ParseNetIP ¶
ParseNetIP turns a string into a net.IP
func SliceAs ¶ added in v0.14.8
func SliceAs[T, V any](vv []T) []V
SliceAs returns a subset of a slice that could be cast into a different type
func SliceAsFn ¶ added in v0.14.8
SliceAsFn returns a subset of a slice that could be cast into a different type, using a helper function.
func SliceContains ¶
func SliceContains[T comparable](a []T, v T) bool
SliceContains tells if a slice contains a given element
func SliceContainsFn ¶
SliceContainsFn tells if a slice contains a given element according to the callback eq
func SliceCopy ¶ added in v0.14.0
func SliceCopy[T any](s []T) []T
SliceCopy makes a shallow copy of a given slice
func SliceCopyFn ¶
SliceCopyFn makes a copy of a slice, optionally modifying in-flight the items using a function. If no function is provided, the destination will be a shallow copy of the source slice.
func SliceEqual ¶ added in v0.13.5
func SliceEqual[T comparable](a, b []T) bool
SliceEqual tells if two slices are equal.
func SliceEqualFn ¶ added in v0.13.5
SliceEqualFn tells if two slices are equal using a comparing helper.
func SliceMap ¶ added in v0.14.1
SliceMap takes a []T1 and uses a function to produce a []T2 by processing each item on the source slice.
func SliceMinus ¶
func SliceMinus[T comparable](a []T, b []T) []T
SliceMinus returns a new slice containing only the elements of one slice not present on the second
func SliceMinusFn ¶
SliceMinusFn returns a new slice containing only elements of slice A that aren't on slice B according to the callback eq
func SliceRandom ¶ added in v0.9.2
SliceRandom returns a random element from a slice if the slice is empty it will return the zero value of the slice type and false
func SliceReplaceFn ¶
SliceReplaceFn replaces or skips entries in a slice
func SliceReverse ¶ added in v0.14.7
func SliceReverse[T any](x []T)
SliceReverse modifies a slice reversing the order of its elements.
func SliceReversed ¶ added in v0.14.7
func SliceReversed[T any](a []T) []T
SliceReversed returns a copy of the slice, in reverse order.
func SliceReversedFn ¶ added in v0.14.7
SliceReversedFn returns a modified copy of the slice, in reverse order.
func SliceSort ¶ added in v0.13.5
SliceSort sorts the slice x in ascending order as determined by the cmp function. This sort is not guaranteed to be stable. cmp(a, b) should return a negative number when a < b, a positive number when a > b and zero when a == b.
func SliceSortFn ¶ added in v0.14.2
SliceSortFn sorts the slice x in ascending order as a less function. This sort is not guaranteed to be stable. less(a, b) should true when a < b
func SliceSortOrdered ¶ added in v0.14.2
func SliceSortOrdered[T Ordered](x []T)
SliceSortOrdered sorts the slice x of an Ordered type in ascending order.
func SliceUnique ¶
func SliceUnique[T comparable](a []T) []T
SliceUnique returns a new slice containing only unique elements
func SliceUniqueFn ¶
SliceUniqueFn returns a new slice containing only unique elements according to the callback eq
func SliceUniquify ¶
func SliceUniquify[T comparable](ptr *[]T) []T
SliceUniquify returns the same slice, reduced to only contain unique elements
func SliceUniquifyFn ¶
SliceUniquifyFn returns the same slice, reduced to only contain unique elements according to the callback eq
func SortedKeys ¶ added in v0.13.5
SortedKeys returns a sorted list of the keys of a map
func SplitAddrPort ¶ added in v0.10.1
SplitAddrPort splits a string containing an IP address and an optional port, and validates it.
func SplitHostPort ¶
SplitHostPort is like net.SplitHostPort but doesn't fail if the port isn't part of the string and it validates it if present. SplitHostPort will also validate the host is a valid IP or name
func Unwrap ¶ added in v0.13.0
Unwrap unwraps one layer of a compound error, ensuring there are no nil entries.
Types ¶
type CallStacker ¶
type CallStacker interface {
CallStack() Stack
}
CallStacker represents an object with a method CallStack() returning a Stack
type Catcher ¶
type Catcher struct {
// contains filtered or unexported fields
}
Catcher is a runner that catches panics
type Complex ¶ added in v0.14.0
type Complex interface { ~complex64 | ~complex128 }
Complex is any complex numeric type.
type CompoundError ¶ added in v0.9.1
type CompoundError struct {
Errs []error
}
A CompoundError can contain more that one error
func (*CompoundError) Append ¶ added in v0.14.5
func (w *CompoundError) Append(err error, note string, args ...any)
Append adds an error to the collection optionally annotated by a formatted string. if err is nil a new error is created unless the note is empty.
func (*CompoundError) AppendError ¶ added in v0.9.1
func (w *CompoundError) AppendError(errs ...error)
AppendError adds an error to the collection, unwrapping other implementers of the Errors interface when possible
func (*CompoundError) AsError ¶ added in v0.9.1
func (w *CompoundError) AsError() error
AsError returns itself as an `error` when there are errors stored, and nil when there aren't
func (*CompoundError) Error ¶ added in v0.9.1
func (w *CompoundError) Error() string
func (*CompoundError) Errors ¶ added in v0.9.1
func (w *CompoundError) Errors() []error
Errors returns the contained slice of errors
func (*CompoundError) Ok ¶ added in v0.9.1
func (w *CompoundError) Ok() bool
Ok tells when there are no errors stored
func (*CompoundError) Unwrap ¶ added in v0.13.0
func (w *CompoundError) Unwrap() []error
Unwrap returns the contained slice of errors
type ContextKey ¶
type ContextKey[T any] struct { // contains filtered or unexported fields }
ContextKey is a type-safe key for a context.Context value
func NewContextKey ¶
func NewContextKey[T any](name string) *ContextKey[T]
NewContextKey creates a new ContextKey bound to the specified type and friendly name
func (*ContextKey[T]) Get ¶
func (ck *ContextKey[T]) Get(ctx context.Context) (T, bool)
Get attempts to extract a value bound to this key in a context.Context For convenience this method will safely operate over a nil receiver.
func (*ContextKey[T]) GoString ¶
func (ck *ContextKey[T]) GoString() string
GoString renders this key in Go syntax for %v
type ErrGroup ¶ added in v0.11.0
ErrGroup handles a group of workers where all are canceled once one fails. As it's based on WaitGroup it also catches panics.
func (*ErrGroup) Cancel ¶ added in v0.11.0
Cancel initiates a shutdown of the group. The returned value indicates if it was the first time.
func (*ErrGroup) Cancelled ¶ added in v0.11.0
func (eg *ErrGroup) Cancelled() <-chan struct{}
Cancelled returns a channel marker to know when the Group has been cancelled and the shutdown has been initiated.
Cancelled() doesn't indicate all workers have finished, for that call ErrGroup.Wait or ErrGroup.Done.
func (*ErrGroup) Context ¶ added in v0.11.0
Context returns the cancellable context used with the workers
func (*ErrGroup) Done ¶ added in v0.11.1
func (eg *ErrGroup) Done() <-chan struct{}
Done returns a channel that gets closed when all workers have finished.
func (*ErrGroup) Go ¶ added in v0.11.0
Go spawns a worker and an optional shutdown routine to be invoked when the ErrGroup is cancelled, otherwise the provided context needs to be monitored and shutdown called.
func (*ErrGroup) GoCatch ¶ added in v0.11.0
func (eg *ErrGroup) GoCatch(run func(context.Context) error, catch func(context.Context, error) error)
GoCatch runs a worker on the Group, with a custom error handler.
func (*ErrGroup) IsCancelled ¶ added in v0.11.0
IsCancelled tells the ErrGroup has been cancelled
func (*ErrGroup) OnError ¶ added in v0.11.0
OnError sets a helper that will be called when a worker returns an error or panics
func (*ErrGroup) SetDefaults ¶ added in v0.11.0
func (eg *ErrGroup) SetDefaults()
SetDefaults fills gaps in the config and initializes the internal structure.
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame represents a function call on the call Stack. This implementation is heavily based on github.com/pkg/errors.Frame but all parts are resolved immediately for later consumption.
func Here ¶
func Here() *Frame
Here returns the Frame corresponding to where it was called, or nil if it wasn't possible
func StackFrame ¶
StackFrame returns the Frame skip levels above from where it was called, or nil if it wasn't possible
func (Frame) FileLine ¶
FileLine returns File name and Line separated by a colon, or only the filename if the Line isn't known
func (Frame) Format ¶
Format formats the frame according to the fmt.Formatter interface. * * %s source file * %d source line * %n function name * %v equivalent to %s:%d * * Format accepts flags that alter the printing of some verbs, as follows: * * %+s function name and path of source file relative to the compile time * GOPATH separated by \n\t (<funcname>\n\t<path>) * %+n full package name followed by function name * %+v equivalent to %+s:%d
func (Frame) FuncName ¶ added in v0.9.10
FuncName returns the name of the function, without the package name
func (Frame) Line ¶
Line returns the file number on the source code corresponding to this Frame, or zero if unknown.
type PanicError ¶
type PanicError struct {
// contains filtered or unexported fields
}
PanicError is an error to be sent via panic, ideally to be caught using slog.Recover()
func NewPanicError ¶
func NewPanicError(skip int, payload any) *PanicError
NewPanicError creates a new PanicError with arbitrary payload
func NewPanicErrorf ¶
func NewPanicErrorf(skip int, format string, args ...any) *PanicError
NewPanicErrorf creates a new PanicError annotated with a string, optionally formatted. %w is expanded.
func NewPanicWrap ¶
func NewPanicWrap(skip int, err error, note string) *PanicError
NewPanicWrap creates a new PanicError wrapping a given error annotated with a single string.
func NewPanicWrapf ¶
func NewPanicWrapf(skip int, err error, format string, args ...any) *PanicError
NewPanicWrapf creates a new PanicError wrapping a given error annotated with a formatted string.
func (*PanicError) CallStack ¶
func (p *PanicError) CallStack() Stack
CallStack returns the call stack associated to this panic() event
func (*PanicError) Error ¶
func (p *PanicError) Error() string
Error returns the payload as a string
func (*PanicError) Recovered ¶
func (p *PanicError) Recovered() any
Recovered returns the payload of the panic
func (*PanicError) Unwrap ¶
func (p *PanicError) Unwrap() error
Unwrap returns the payload if it's and error
type Recovered ¶
Recovered is an error caught from a panic call
func AsRecovered ¶
AsRecovered receives the value from recover() and wraps it as a Recovered error
type SpinLock ¶ added in v0.15.3
type SpinLock uint32
SpinLock is a simple CompareAndSwap locking mechanism.
func (*SpinLock) Lock ¶ added in v0.15.3
func (sl *SpinLock) Lock()
Lock blocks until it can acquire the lock
type Stack ¶
type Stack []Frame
Stack is an snapshot of the call stack in the form of an array of Frames.
func StackTrace ¶
StackTrace returns a snapshot of the call stack starting skip levels above from where it was called, on an empty array if it wasn't possible
type TemporaryError ¶ added in v0.13.2
type TemporaryError struct {
// contains filtered or unexported fields
}
TemporaryError is an error wrapper that satisfies IsTimeout() and IsTemporary()
func (*TemporaryError) Error ¶ added in v0.13.2
func (w *TemporaryError) Error() string
func (*TemporaryError) IsTemporary ¶ added in v0.13.2
func (*TemporaryError) IsTemporary() bool
IsTemporary tells this error is temporary.
func (*TemporaryError) IsTimeout ¶ added in v0.13.2
func (w *TemporaryError) IsTimeout() bool
IsTimeout tells if this error is a time-out or not.
func (*TemporaryError) Temporary ¶ added in v0.13.2
func (*TemporaryError) Temporary() bool
Temporary tells this error is temporary.
func (*TemporaryError) Timeout ¶ added in v0.13.2
func (w *TemporaryError) Timeout() bool
Timeout tells if this error is a time-out or not.
type Unwrappable ¶
Unwrappable represents an error that can be Unwrap() to get the cause
type WaitGroup ¶
type WaitGroup struct {
// contains filtered or unexported fields
}
WaitGroup is a safer way to run workers
func (*WaitGroup) Done ¶ added in v0.11.1
func (wg *WaitGroup) Done() <-chan struct{}
Done returns a channel that gets closed when all workers have finished.
func (*WaitGroup) GoCatch ¶
GoCatch spawns a supervised goroutine, and uses a given function to intercept the returned error
type WrappedError ¶
type WrappedError struct {
// contains filtered or unexported fields
}
WrappedError is an annotated error that can be Unwrapped
func (*WrappedError) Error ¶
func (w *WrappedError) Error() string
func (*WrappedError) Unwrap ¶
func (w *WrappedError) Unwrap() error