mustutils

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyToErr

func AnyToErr(v any) error

AnyToErr converts a recovered panic value into an error: nil stays nil, an error is wrapped as "panicked", and anything else is formatted into one.

func DoInBackground added in v1.0.1

func DoInBackground(ctx context.Context, fn func(ctx context.Context) error)

DoInBackground runs fn in a new goroutine, recovering panics and logging errors. The goroutine's context keeps ctx's values but is detached from its cancellation and capped with a 3-minute timeout, so fn outlives the caller.

func Must

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

Must returns obj, or panics if err is non-nil. Use only where an error is a programming error, e.g. package init.

func MustNoReturn

func MustNoReturn(err error)

MustNoReturn panics if err is non-nil, for calls that only return an error.

func MustOk

func MustOk[T any](obj T, ok bool) T

MustOk returns obj, or panics if ok is false. Handy for the comma-ok forms (map lookup, type assertion).

func WithRecover

func WithRecover(f func() error) func() error

WithRecover decorates f so that a panic is recovered and returned as an error wrapped with "recovered"; a normal error from f is returned as-is.

func WithRecoverAndLog

func WithRecoverAndLog(f func(ctx context.Context) error) func(ctx context.Context)

WithRecoverAndLog decorates f with panic recovery and logs any resulting error (from a panic or a returned error) via the ctx logger.

Types

This section is empty.

Jump to

Keyboard shortcuts

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