Documentation
¶
Overview ¶
Package basefn provide some no-dependents util functions
Index ¶
- func CallOn(cond bool, fn ErrFunc) error
- func CallOrElse(cond bool, okFn, elseFn ErrFunc) error
- func ErrOnFail(cond bool, err error) error
- func FirstOr[T any](sl []T, elseVal T) T
- func Must[T any](v T, err error) T
- func MustIgnore(_ any, err error)
- func MustOK(err error)
- func OrError(cond bool, err error) error
- func OrReturn[T any](cond bool, okFn, elseFn func() T) T
- func OrValue[T any](cond bool, okVal, elVal T) T
- func PanicErr(err error)
- func PanicIf(cond bool, fmtAndArgs ...any)
- func Panicf(format string, v ...any)
- type ErrFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CallOrElse ¶
CallOrElse call okFunc() on condition is true, else call elseFn()
func Must ¶
Must return like (v, error). will panic on error, otherwise return v.
Usage:
// old
v, err := fn()
if err != nil {
panic(err)
}
// new
v := goutil.Must(fn())
func MustIgnore ¶
MustIgnore for return like (v, error). Ignore return v and will panic on error.
Useful for io, file operation func: (n int, err error)
Usage:
// old
_, err := fn()
if err != nil {
panic(err)
}
// new
basefn.MustIgnore(fn())
func OrReturn ¶
OrReturn call okFunc() on condition is true, else call elseFn()
like expr: if cond { okFunc() } else { elseFn() }
Types ¶
Click to show internal directories.
Click to hide internal directories.