runtimex

package
v3.19.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: GPL-3.0 Imports: 3 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var BuildInfo = &BuildInfoRecord{}

BuildInfo is the singleton containing build-time information.

Functions

func Assert added in v3.16.0

func Assert(assertion bool, message string)

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

func PanicIfNil(v any, message string)

PanicIfNil calls panic if the given interface is nil. The type passed to panic is an error constructed using errors.New(message).

func PanicIfTrue

func PanicIfTrue(assertion bool, message string)

PanicIfTrue calls panic if assertion is true. The type passed to panic is an error constructed using errors.New(message).

func PanicOnError

func PanicOnError(err error, message string)

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

func Try1[T1 any](v1 T1, err error) T1

Try1 is like Try0 but supports functions returning one values and an error.

func Try2 added in v3.17.0

func Try2[T1, T2 any](v1 T1, v2 T2, err error) (T1, T2)

Try2 is like Try1 but supports functions returning two values and an error.

func Try3 added in v3.17.0

func Try3[T1, T2, T3 any](v1 T1, v2 T2, v3 T3, err error) (T1, T2, T3)

Try3 is like Try2 but supports functions returning three 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

type WarningLogger interface {
	Warnf(format string, v ...any)
}

WarningLogger is a logger that emits formatted warnings. We cannot directly use the definition inside the [model] package because [model] depends on runtimex.

Jump to

Keyboard shortcuts

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