mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-04-02 06:43:06 -04:00
Bumps [github.com/gookit/config/v2](https://github.com/gookit/config) from 2.1.8 to 2.2.2. - [Release notes](https://github.com/gookit/config/releases) - [Commits](https://github.com/gookit/config/compare/v2.1.8...v2.2.2) --- updated-dependencies: - dependency-name: github.com/gookit/config/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
38 lines
753 B
Go
38 lines
753 B
Go
package goutil
|
|
|
|
import "github.com/gookit/goutil/stdutil"
|
|
|
|
// FuncName get func name
|
|
func FuncName(f any) string {
|
|
return stdutil.FuncName(f)
|
|
}
|
|
|
|
// Go is a basic promise implementation: it wraps calls a function in a goroutine
|
|
// and returns a channel which will later return the function's return value.
|
|
func Go(f func() error) error {
|
|
ch := make(chan error)
|
|
go func() {
|
|
ch <- f()
|
|
}()
|
|
return <-ch
|
|
}
|
|
|
|
// ErrFunc type
|
|
type ErrFunc func() error
|
|
|
|
// CallOn call func on condition is true
|
|
func CallOn(cond bool, fn ErrFunc) error {
|
|
if cond {
|
|
return fn()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// CallOrElse call okFunc() on condition is true, else call elseFn()
|
|
func CallOrElse(cond bool, okFn, elseFn ErrFunc) error {
|
|
if cond {
|
|
return okFn()
|
|
}
|
|
return elseFn()
|
|
}
|