// Package basefn provide some no-dependents util functions
package basefnimport ()// Panicf format panic message use fmt.Sprintffunc ( string, ...any) { panic(fmt.Sprintf(, ...)) }// PanicIf if cond = true, panics with an error messagefunc ( bool, ...any) {if {panic(errors.New(comfunc.FormatWithArgs())) }}// PanicErr panics if error is not emptyfunc ( error) {if != nil {panic() }}// MustOK if error is not empty, will panicfunc ( error) {if != nil {panic() }}// 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 [ any]( , error) {if != nil {panic() }return}// 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 ( any, error) { PanicErr() }// ErrOnFail return input error on cond is false, otherwise return nilfunc ( bool, error) error {returnOrError(, )}// OrError return input error on cond is false, otherwise return nilfunc ( bool, error) error {if ! {return }returnnil}// FirstOr get first elem or elseValfunc [ any]( [], ) {iflen() > 0 {return [0] }return}// OrValue get. like: if cond { okVal } else { elVal }func [ any]( bool, , ) {if {return }return}// OrReturn call okFunc() on condition is true, else call elseFn()//// like expr: if cond { okFunc() } else { elseFn() }func [ any]( bool, , func() ) {if {return () }return ()}// ErrFunc typetypeErrFuncfunc() error// CallOn call func on condition is truefunc ( bool, ErrFunc) error {if {return () }returnnil}// CallOrElse call okFunc() on condition is true, else call elseFn()func ( bool, , ErrFunc) error {if {return () }return ()}
The pages are generated with Goldsv0.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.