must

package
v0.0.0-...-b4a68df Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package must provides functions for handling errors and panics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Catch

func Catch(err *error)

func Get0

func Get0[T1, T2 any](v1 T1, v2 T2) T1

func Get1

func Get1[T1, T2 any](v1 T1, v2 T2) T2

func Ok

func Ok[T any](v T, err error) (zero T)

Ok takes a function that returns a value and error and returns only a value, otherwise it panics.

func Recover

func Recover(errs ...error)

Recover can be used to recover from panics within a function. It must be called with defer where the panic occurs. If errors are provided, Recover will only recover from panics that match one of the errors. If no errors are provided, then all panics will be recovered and logged using the default slog logger.

func RecoverFunc

func RecoverFunc(fn func(r any) bool)

RecoverFunc allows recovering a panic within a function. If the function provided returns true, then the panic is recovered, otherwise panic is called with the original recovered value.

Types

This section is empty.

Jump to

Keyboard shortcuts

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