Documentation
¶
Index ¶
- func BeTrue(ok bool)
- func BeTrueV[V any](v V, ok bool) V
- func BeTrueWrap(ok bool, msg string, args ...any)
- func IdenticalTypes(t1, t2 any) bool
- func NoError(err error)
- func NoErrorV[V any](v V, err error) V
- func NoErrorWrap(err error, msg string, args ...any)
- func NotNilV[V any](v V) V
- func NotNilWrap(v any, msg string, args ...any)
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 ¶
Example ¶
fmt.Println(must.BeTrueV(ReturnIntTrue())) defer func() { fmt.Println(recover()) }() _ = must.BeTrueV(ReturnIntFalse())
Output: 100 must be true
func BeTrueWrap ¶
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 NoError ¶
func NoError(err error)
Example ¶
must.NoError(ReturnNoError()) defer func() { fmt.Println(recover()) }() must.NoError(ReturnError())
Output: some error
func NoErrorV ¶
Example ¶
fmt.Println(must.NoErrorV(ReturnIntNoError())) defer func() { fmt.Println(recover()) }() must.NoErrorV(ReturnIntError())
Output: 100 some error
func NoErrorWrap ¶
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
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.