package basefn
Import Path
github.com/gookit/goutil/x/basefn (on go.dev)
Dependency Relation
imports 3 packages, and imported by one package
Involved Source Files
Package basefn provide some no-dependents util functions
Package-Level Type Names (only one)
Package-Level Functions (total 13)
CallOn call func on condition is true
CallOrElse call okFunc() on condition is true, else call elseFn()
ErrOnFail return input error on cond is false, otherwise return nil
Type Parameters:
T: any
FirstOr get first elem or elseVal
Type Parameters:
T: any
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())
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())
MustOK if error is not empty, will panic
OrError return input error on cond is false, otherwise return nil
Type Parameters:
T: any
OrReturn call okFunc() on condition is true, else call elseFn()
like expr: if cond { okFunc() } else { elseFn() }
Type Parameters:
T: any
OrValue get. like: if cond { okVal } else { elVal }
PanicErr panics if error is not empty
Panicf format panic message use fmt.Sprintf
PanicIf if cond = true, panics with an error message
![]() |
The pages are generated with Golds v0.8.4. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |