Skip to content

Import path: gitlab.soludian.com/soludian/fountain/libs/base/fn

fn

go
import "gitlab.soludian.com/soludian/fountain/libs/base/fn"

Package fn provide some no-dependents util functions

Index

func CallOn

go
func CallOn(cond bool, fn ErrFunc) error

CallOn call func on condition is true

func CallOrElse

go
func CallOrElse(cond bool, okFn, elseFn ErrFunc) error

CallOrElse call okFunc() on condition is true, else call elseFn()

func ErrOnFail

go
func ErrOnFail(cond bool, err error) error

ErrOnFail return input error on cond is false, otherwise return nil

func FirstOr

go
func FirstOr[T any](sl []T, elseVal T) T

FirstOr get first elem or elseVal

func Must

go
func Must[T any](v T, err error) T

Must if error is not empty, will panic

func MustOK

go
func MustOK(err error)

MustOK if error is not empty, will panic

func OrError

go
func OrError(cond bool, err error) error

OrError return input error on cond is false, otherwise return nil

func OrReturn

go
func OrReturn[T any](cond bool, okFn, elseFn func() T) T

OrReturn call okFunc() on condition is true, else call elseFn()

func OrValue

go
func OrValue[T any](cond bool, okVal, elVal T) T

OrValue get

func PanicErr

go
func PanicErr(err error)

PanicErr panics if error is not empty

func PanicIf

go
func PanicIf(cond bool, fmtAndArgs ...any)

PanicIf if cond = true, panics with error message

func Panicf

go
func Panicf(format string, v ...any)

Panicf format panic message use fmt.Sprintf

type ErrFunc

ErrFunc type

go
type ErrFunc func() error

Generated by gomarkdoc