Documentation ¶
Overview ¶
Package runtimex contains runtime extensions. This package is inspired to https://pkg.go.dev/github.com/m-lab/go/rtx, except that it's simpler.
Index ¶
- Variables
- func Assert(assertion bool, message string)
- func CatchLogAndIgnorePanic(logger WarningLogger, prefix string)
- func PanicIfNil(v any, message string)
- func PanicIfTrue(assertion bool, message string)
- func PanicOnError(err error, message string)
- func Try0(err error)
- func Try1[T1 any](v1 T1, err error) T1
- func Try2[T1, T2 any](v1 T1, v2 T2, err error) (T1, T2)
- func Try3[T1, T2, T3 any](v1 T1, v2 T2, v3 T3, err error) (T1, T2, T3)
- type BuildInfoRecord
- type WarningLogger
Constants ¶
This section is empty.
Variables ¶
var BuildInfo = &BuildInfoRecord{}
BuildInfo is the singleton containing build-time information.
Functions ¶
func Assert ¶ added in v3.16.0
Assert calls panic if assertion is false. The type passed to panic is an error constructed using errors.New(message).
func CatchLogAndIgnorePanic ¶ added in v3.19.0
func CatchLogAndIgnorePanic(logger WarningLogger, prefix string)
CatchLogAndIgnorePanic is a function that catches and ignores panics. You can invoke this function as follows:
defer runtimex.CatchLogAndIgnorePanic(logger, "prefix.......")
and rest assured that any panic will not propagate further. You should typically only use this function when writing testing code.
This function will emit a warning message prefixed using the given prefix and emitted using the given logger in case it intercepts and suppresses a panic.
func PanicIfNil ¶ added in v3.14.0
PanicIfNil calls panic if the given interface is nil. The type passed to panic is an error constructed using errors.New(message).
func PanicIfTrue ¶
PanicIfTrue calls panic if assertion is true. The type passed to panic is an error constructed using errors.New(message).
func PanicOnError ¶
PanicOnError calls panic() if err is not nil. The type passed to panic is an error type wrapping the original error.
func Try0 ¶ added in v3.17.0
func Try0(err error)
Try0 calls runtimex.PanicOnError if err is not nil.
func Try1 ¶ added in v3.17.0
Try1 is like Try0 but supports functions returning one values and an error.
Types ¶
type BuildInfoRecord ¶ added in v3.17.0
type BuildInfoRecord struct { // GoVersion is the version of go with which this code // was compiled or an empty string. GoVersion string // VcsModified indicates whether the tree was dirty. VcsModified string // VcsRevision is the VCS revision we compiled. VcsRevision string // VcsTime is the time of the revision we're building. VcsTime string // VcsTool is the VCS tool being used. VcsTool string }
BuildInfoRecord contains build-time information.
type WarningLogger ¶ added in v3.19.0
WarningLogger is a logger that emits formatted warnings. We cannot directly use the definition inside the [model] package because [model] depends on runtimex.