Documentation
¶
Overview ¶
Package utils is a basic utilities.
Index ¶
- Variables
- func AddLogWriter(writer io.Writer)
- func Assert(b bool, a ...any)
- func Assertf(b bool, format string, a ...any)
- func Assign[T any](dst *T, src T) T
- func Bind[T any](err error, fn func() (T, error)) (T, error)
- func Bind0(err error, fn func() error) error
- func Bind1[T any](err error, fn func() (T, error)) (T, error)
- func Bind2[T any, U any](err error, fn func() (T, U, error)) (T, U, error)
- func Catch(errRef *error, fns ...func(error))
- func Debugger()
- func E(args ...any) error
- func Elvis[T comparable](t T, f T) T
- func ElvisF[T comparable](t func() T, f func() T) (ret T)
- func Err[T any](err error) (T, error)
- func ErrorAs[T error](err error) (t T)
- func Expect(err error, expectedErrors ...error)
- func Ignore[T any](T, ...any)
- func Let[T any](err error, fn func() T) T
- func Let0(err error, fn func())
- func Let1[T any](err error, fn func() T) T
- func Let2[T any, U any](err error, fn func() (T, U)) (T, U)
- func LogPrint(v ...interface{})
- func LogPrintf(format string, v ...interface{})
- func LogPrintln(v ...interface{})
- func Must(args ...any)
- func Nil[T any]() (t T)
- func Ok[T any](value T) (T, error)
- func P[T any](v T) *T
- func PMap[T any, U any](pt *T, fn func(*T) *U) *U
- func PR[T any](value T, err error) *valueErrorContext[*T]
- func Ptr[T any](v T) *T
- func PtrMap[T any, U any](pt *T, fn func(*T) *U) *U
- func PtrResult[T any](value T, err error) *valueErrorContext[*T]
- func R[T any](value T, err error) *valueErrorContext[T]
- func RecoverPanicObject[T comparable](errRef *error, target T, fn func() error)
- func RecoverPanicType[T any](errRef *error, fn func(T) error)
- func Result[T any](value T, err error) *valueErrorContext[T]
- func Ternary[T any](cond bool, t T, f T) T
- func TernaryF[T any](cond bool, t func() T, f func() T) (ret T)
- func TernaryF2[T any, U any](cond bool, t func() (T, U), f func() (T, U)) (ret1 T, ret2 U)
- func Then(err error, fn func() error) error
- func Throw(err error)
- func ThrowIf(err error)
- func V[T any](value T, err error) T
- func V2[T any, U any](value1 T, value2 U, err error) (T, U)
- func V3[T any, U any, V any](value1 T, value2 U, value3 V, err error) (T, U, V)
- func Value[T any](value T, err error) T
- func Value2[T any, U any](value1 T, value2 U, err error) (T, U)
- func Value3[T any, U any, V any](value1 T, value2 U, value3 V, err error) (T, U, V)
- func WithStack(err error) error
Constants ¶
This section is empty.
Variables ¶
var A = Assert
A is a shorthand for Assert.
var V0 = Must
V0 returns no value. If err is not nil, it panics. Deprecated: Use Must instead.
Functions ¶
func AddLogWriter ¶ added in v0.0.2024072645
AddLogWriter adds a writer to the list of log writers.
func Assertf ¶ added in v0.0.2024073012
Assertf panics with the given message if the condition is false.
func Assign ¶ added in v0.0.2024080445
func Assign[T any](dst *T, src T) T
Assign assigns a value to a pointer and returns the assigned value.
func Bind ¶
Bind returns the result of the given function that can fail if err is nil, otherwise the error.
func Bind2 ¶
Bind2 returns the result of the given function that can fail if err is nil, otherwise the error.
func Catch ¶ added in v0.0.2024021245
Catch recovers from panics and handles errors through callbacks.
func Debugger ¶ added in v0.0.2024021544
func Debugger()
Debugger waits for a debugger to connect if the environment variable $WAIT_DEBUGGER is set or the first argument is "--wait-debugger"
func E ¶ added in v0.0.2024022328
E extracts an error from the last argument, returning nil if no error is found.
func Elvis ¶ added in v0.0.2024072420
func Elvis[T comparable](t T, f T) T
Elvis returns the first value if it is not empty, otherwise the second value. // Elvis operator - Wikipedia https://en.wikipedia.org/wiki/Elvis_operator
func ElvisF ¶ added in v0.0.2024072421
func ElvisF[T comparable]( t func() T, f func() T, ) (ret T)
ElvisF returns the result of the first function if it is not empty, otherwise the result of the second function.
func ErrorAs ¶ added in v0.0.2024080520
ErrorAs returns the error as type T if possible, otherwise returns the zero value.
func Expect ¶ added in v0.0.2024073012
Expect panics if the error is not nil and not one of the expected errors.
func Let0 ¶
func Let0(err error, fn func())
Let0 calls the given function if err is nil and returns nothing.
func LogPrint ¶ added in v0.0.2024072645
func LogPrint(v ...interface{})
LogPrint writes output to all registered log writers.
func LogPrintf ¶ added in v0.0.2024072645
func LogPrintf(format string, v ...interface{})
LogPrintf writes formatted output to all registered log writers.
func LogPrintln ¶ added in v0.0.2024072645
func LogPrintln(v ...interface{})
LogPrintln writes output with a newline to all registered log writers.
func PR ¶ added in v0.0.2024022348
PR returns a pointer + error result context. Deprecated: Use PtrResult instead.
func R ¶ added in v0.0.2024021526
R returns a value + error result context. Deprecated: Use Result instead.
func RecoverPanicObject ¶
func RecoverPanicObject[T comparable](errRef *error, target T, fn func() error)
RecoverPanicObject recovers from panics matching a specific object value.
func RecoverPanicType ¶
RecoverPanicType recovers from panics of a specific type.
func Ternary ¶
Ternary returns the first value if cond is true, otherwise the second value. // Ternary conditional operator - Wikipedia https://en.wikipedia.org/wiki/Ternary_conditional_operator
func TernaryF ¶
TernaryF returns the result of the first function if cond is true, otherwise the result of the second function.
func TernaryF2 ¶ added in v0.0.2024072004
TernaryF2 returns the result of the first function if cond is true, otherwise the result of the second function.
func Throw ¶ added in v0.0.2024080445
func Throw(err error)
Throw panics with the given error wrapped with stack trace.
func ThrowIf ¶ added in v0.0.2024080537
func ThrowIf(err error)
ThrowIf panics with the given error if it is not nil.
func V ¶ added in v0.0.2024022328
V returns the value. If err is not nil, it panics. Deprecated: Use Value instead.
func V2 ¶ added in v0.0.2024070104
V2 returns two values. If err is not nil, it panics. Deprecated: Use Value2 instaed.
func V3 ¶ added in v0.0.2024070250
V3 returns three values. If err is not nil, it panics. Deprecated: Use Value3 instaed.s
Types ¶
This section is empty.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
fetch
command
Fetch command implementation.
|
Fetch command implementation. |
|
foo
command
Entry
|
Entry |
|
Package main is a main package.
|
Package main is a main package. |
|
Package fs is utilities for filesystem.
|
Package fs is utilities for filesystem. |
|
Package funcopt provides Functional Option Pattern helpers.
|
Package funcopt provides Functional Option Pattern helpers. |
|
Package initwait is a group of functions to wait until a debugger connects.
|
Package initwait is a group of functions to wait until a debugger connects. |
|
Package net is network utilities.
|
Package net is network utilities. |