must

package
v0.0.33 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: MIT Imports: 2 Imported by: 3

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeTrue

func BeTrue(ok bool)
Example
must.BeTrue(ReturnTrue())

defer func() {
	fmt.Println(recover())
}()
must.BeTrue(ReturnFalse())
Output:

must be true

func BeTrueV

func BeTrueV[V any](v V, ok bool) V
Example
fmt.Println(must.BeTrueV(ReturnIntTrue()))

defer func() {
	fmt.Println(recover())
}()
_ = must.BeTrueV(ReturnIntFalse())
Output:

100
must be true

func BeTrueWrap

func BeTrueWrap(ok bool, msg string, args ...any)
Example
must.BeTrueWrap(ReturnTrue(), "any")

defer func() {
	fmt.Println(recover())
}()
must.BeTrueWrap(ReturnFalse(), "required exists")
Output:

must be true: required exists

func IdenticalTypes added in v0.0.33

func IdenticalTypes(t1, t2 any) bool

func NoError

func NoError(err error)
Example
must.NoError(ReturnNoError())

defer func() {
	fmt.Println(recover())
}()
must.NoError(ReturnError())
Output:

some error

func NoErrorV

func NoErrorV[V any](v V, err error) V
Example
fmt.Println(must.NoErrorV(ReturnIntNoError()))

defer func() {
	fmt.Println(recover())
}()
must.NoErrorV(ReturnIntError())
Output:

100
some error

func NoErrorWrap

func NoErrorWrap(err error, msg string, args ...any)
Example
must.NoErrorWrap(ReturnNoError(), "any")

defer func() {
	fmt.Println(recover())
}()
must.NoErrorWrap(ReturnError(), "some message: %d", 10)
Output:

some message: 10: some error

func NotNilV added in v0.0.14

func NotNilV[V any](v V) V
Example
rv := reflect.ValueOf(struct {
	V0 any
	V7 error
	V8 reflect.Type
	V1 chan error
	V2 func()
	V3 *int
	V4 unsafe.Pointer
	V5 []int
	V6 map[string]int
}{})
for i := range rv.NumField() {
	func(v any) {
		defer func() {
			if err := recover(); err != nil {
				fmt.Println(err)
			}
		}()
		must.NotNilV(v)
	}(rv.Field(i).Interface())
}
fmt.Println(must.NotNilV(1))
fmt.Println(*must.NotNilV(new(int)))

defer func() {
	if err := recover(); err != nil {
		fmt.Println(err)
	}
}()
must.NotNilWrap((*int)(nil), "business message %v", 100)
Output:

must not nil, but got invalid value
must not nil, but got invalid value
must not nil, but got invalid value
must not nil for type `chan error`
must not nil for type `func()`
must not nil for type `*int`
must not nil for type `unsafe.Pointer`
must not nil for type `[]int`
must not nil for type `map[string]int`
1
0
must not nil for type `*int` business message 100

func NotNilWrap added in v0.0.15

func NotNilWrap(v any, msg string, args ...any)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳