Documentation ¶
Overview ¶
Package tool Useful general purpose tool
Index ¶
- func Catch(fn func(err error))
- func Console(obj ...interface{})
- func ConvertSlice[T any, Y any](srcSlice []T, destTypedValue Y) []Y
- func Err(args ...any) error
- func ExecTemplate(templateText string, templateVars any) string
- func In[T comparable](needle T, haystack ...T) bool
- func IsZero[T comparable](v T) bool
- func MultiMute[T any](a ...T) []T
- func Must(err error, verbose ...bool)
- func MustReturn[T any](val T, err error) T
- func NonZero[T comparable](ts ...T) T
- func Objectify[T ~[]byte | ~string](in T, target any) bool
- func Ptr[T any](n T) *T
- func RandInt[num constraints.Signed](min, max num) num
- func Recoverer[num constraints.Integer](maxPanics num, f func(), jobID ...string) (recovErr error)
- func RetryFunc[num constraints.Signed](attempts num, sleep time.Duration, f func() error) error
- func Return[T any](val T, _ error) T
- func SetLogger(l StdLogger)
- func Strtr(subject string, oldToNew map[string]string) string
- func Try(err error, verbose ...bool) bool
- type LogRus
- type StdLogger
- type Varchar
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Catch ¶ added in v1.0.2
func Catch(fn func(err error))
Catch Recovers from panic and callbacks with error If error is not catchableError, it will panic again May be used as defer, coupled with MustReturn or Must, to override named return values
Usage:
func example() (val *http.Request, err error) { defer tool.Catch(func(caught error) { err = caught }) val = tool.MustReturn(funcThatReturnsValAndErr()) // <- this will be caught if err!=nil panic(errors.New("some error")) // <- this will not be caught return }
func Console ¶
func Console(obj ...interface{})
Console Prints %+v of arguments, great to debug stuff
func ConvertSlice ¶ added in v1.2.0
ConvertSlice Return a new slice as `[]dstTypedValue.(type)` cast from the `srcSlice`
func ExecTemplate ¶ added in v1.0.8
func MultiMute ¶ added in v1.2.0
func MultiMute[T any](a ...T) []T
MultiMute Ignores errors, returns slice of results.
func MustReturn ¶ added in v1.0.2
MustReturn Tolerates no errors, returns value.
func NonZero ¶ added in v1.0.7
func NonZero[T comparable](ts ...T) T
NonZero Returns first non-zero value or zero value if all values are zero
func RandInt ¶
func RandInt[num constraints.Signed](min, max num) num
RandInt Return a random number in specified range.
func Recoverer ¶
func Recoverer[num constraints.Integer](maxPanics num, f func(), jobID ...string) (recovErr error)
Recoverer Recovers job from panic, if maxPanics<0 then infinitely
func SetLogger ¶
func SetLogger(l StdLogger)
SetLogger Sets tool package logger, pass nil to disable logging