Documentation
¶
Index ¶
- func Invoke[R1 any](ctx context.Context, fn func() (R1, error)) (R1, error)
- func Invoke0(ctx context.Context, fn func() error) error
- func Invoke1[R1 any](ctx context.Context, fn func() (R1, error)) (R1, error)
- func Invoke2[R1 any, R2 any](ctx context.Context, fn func() (R1, R2, error)) (R1, R2, error)
- func Invoke3[R1 any, R2 any, R3 any](ctx context.Context, fn func() (R1, R2, R3, error)) (R1, R2, R3, error)
- func Invoke4[R1 any, R2 any, R3 any, R4 any](ctx context.Context, fn func() (R1, R2, R3, R4, error)) (R1, R2, R3, R4, error)
- func Invoke5[R1 any, R2 any, R3 any, R4 any, R5 any](ctx context.Context, fn func() (R1, R2, R3, R4, R5, error)) (R1, R2, R3, R4, R5, error)
- func Invoke6[R1 any, R2 any, R3 any, R4 any, R5 any, R6 any](ctx context.Context, fn func() (R1, R2, R3, R4, R5, R6, error)) (R1, R2, R3, R4, R5, R6, error)
- func InvokeWith[R1 any](fn func() (R1, error), opts ...CallInvokeWithOption) (R1, error)
- func InvokeWith0(fn func() error, opts ...CallInvokeWithOption) error
- func InvokeWith1[R1 any](fn func() (R1, error), opts ...CallInvokeWithOption) (R1, error)
- func InvokeWith2[R1 any, R2 any](fn func() (R1, R2, error), opts ...CallInvokeWithOption) (R1, R2, error)
- func InvokeWith3[R1 any, R2 any, R3 any](fn func() (R1, R2, R3, error), opts ...CallInvokeWithOption) (R1, R2, R3, error)
- func InvokeWith4[R1 any, R2 any, R3 any, R4 any](fn func() (R1, R2, R3, R4, error), opts ...CallInvokeWithOption) (R1, R2, R3, R4, error)
- func InvokeWith5[R1 any, R2 any, R3 any, R4 any, R5 any](fn func() (R1, R2, R3, R4, R5, error), opts ...CallInvokeWithOption) (R1, R2, R3, R4, R5, error)
- func InvokeWith6[R1 any, R2 any, R3 any, R4 any, R5 any, R6 any](fn func() (R1, R2, R3, R4, R5, R6, error), opts ...CallInvokeWithOption) (R1, R2, R3, R4, R5, R6, error)
- func InvokeWithTimeout[R1 any](fn func() (R1, error), timeout time.Duration) (R1, error)
- func InvokeWithTimeout0(fn func() error, timeout time.Duration) error
- func InvokeWithTimeout1[R1 any](fn func() (R1, error), timeout time.Duration) (R1, error)
- func InvokeWithTimeout2[R1 any, R2 any](fn func() (R1, R2, error), timeout time.Duration) (R1, R2, error)
- func InvokeWithTimeout3[R1 any, R2 any, R3 any](fn func() (R1, R2, R3, error), timeout time.Duration) (R1, R2, R3, error)
- func InvokeWithTimeout4[R1 any, R2 any, R3 any, R4 any](fn func() (R1, R2, R3, R4, error), timeout time.Duration) (R1, R2, R3, R4, error)
- func InvokeWithTimeout5[R1 any, R2 any, R3 any, R4 any, R5 any](fn func() (R1, R2, R3, R4, R5, error), timeout time.Duration) (R1, R2, R3, R4, R5, error)
- func InvokeWithTimeout6[R1 any, R2 any, R3 any, R4 any, R5 any, R6 any](fn func() (R1, R2, R3, R4, R5, R6, error), timeout time.Duration) (R1, R2, R3, R4, R5, R6, error)
- func May[T any](val T, err any, messageArgs ...any) T
- func May0(err any, messageArgs ...any)
- func May1[T any](t1 T, err any, messageArgs ...any) T
- func May2[T1 any, T2 any](t1 T1, t2 T2, err any, messageArgs ...any) (T1, T2)
- func May3[T1 any, T2 any, T3 any](t1 T1, t2 T2, t3 T3, err any, messageArgs ...any) (T1, T2, T3)
- func May4[T1 any, T2 any, T3 any, T4 any](t1 T1, t2 T2, t3 T3, t4 T4, err any, messageArgs ...any) (T1, T2, T3, T4)
- func May5[T1 any, T2 any, T3 any, T4 any, T5 any](t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, err any, messageArgs ...any) (T1, T2, T3, T4, T5)
- func May6[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any](t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, err any, messageArgs ...any) (T1, T2, T3, T4, T5, T6)
- func SetHandlers(handler ...MayHandler)
- func SetLoggers(logger ...Logger)
- type CallInvokeWithOption
- type Logger
- type MayHandler
- type MayInvoker
- func (h MayInvoker) CollectAsError() error
- func (h MayInvoker) CollectAsErrors() []error
- func (h MayInvoker) HandleErrors(handler func(errs []error))
- func (h MayInvoker) HandleErrorsWithReturn(handler func(errs []error) error) error
- func (f *MayInvoker[T]) Invoke(t1 T, err any, messageArgs ...any) T
- func (f *MayInvoker[T]) Use(handler ...MayHandler) *MayInvoker[T]
- type MayInvoker0
- func (h MayInvoker0) CollectAsError() error
- func (h MayInvoker0) CollectAsErrors() []error
- func (h MayInvoker0) HandleErrors(handler func(errs []error))
- func (h MayInvoker0) HandleErrorsWithReturn(handler func(errs []error) error) error
- func (f *MayInvoker0) Invoke(anyErr any, messageArgs ...any)
- func (f *MayInvoker0) Use(handler ...MayHandler) *MayInvoker0
- type MayInvoker2
- func (h MayInvoker2) CollectAsError() error
- func (h MayInvoker2) CollectAsErrors() []error
- func (h MayInvoker2) HandleErrors(handler func(errs []error))
- func (h MayInvoker2) HandleErrorsWithReturn(handler func(errs []error) error) error
- func (f *MayInvoker2[T1, T2]) Invoke(t1 T1, t2 T2, err any, messageArgs ...any) (T1, T2)
- func (f *MayInvoker2[T1, T2]) Use(handler ...MayHandler) *MayInvoker2[T1, T2]
- type MayInvoker3
- func (h MayInvoker3) CollectAsError() error
- func (h MayInvoker3) CollectAsErrors() []error
- func (h MayInvoker3) HandleErrors(handler func(errs []error))
- func (h MayInvoker3) HandleErrorsWithReturn(handler func(errs []error) error) error
- func (f *MayInvoker3[T1, T2, T3]) Invoke(t1 T1, t2 T2, t3 T3, err any, messageArgs ...any) (T1, T2, T3)
- func (f *MayInvoker3[T1, T2, T3]) Use(handler ...MayHandler) *MayInvoker3[T1, T2, T3]
- type MayInvoker4
- func (h MayInvoker4) CollectAsError() error
- func (h MayInvoker4) CollectAsErrors() []error
- func (h MayInvoker4) HandleErrors(handler func(errs []error))
- func (h MayInvoker4) HandleErrorsWithReturn(handler func(errs []error) error) error
- func (f *MayInvoker4[T1, T2, T3, T4]) Invoke(t1 T1, t2 T2, t3 T3, t4 T4, err any, messageArgs ...any) (T1, T2, T3, T4)
- func (f *MayInvoker4[T1, T2, T3, T4]) Use(handler ...MayHandler) *MayInvoker4[T1, T2, T3, T4]
- type MayInvoker5
- func (h MayInvoker5) CollectAsError() error
- func (h MayInvoker5) CollectAsErrors() []error
- func (h MayInvoker5) HandleErrors(handler func(errs []error))
- func (h MayInvoker5) HandleErrorsWithReturn(handler func(errs []error) error) error
- func (f *MayInvoker5[T1, T2, T3, T4, T5]) Invoke(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, err any, messageArgs ...any) (T1, T2, T3, T4, T5)
- func (f *MayInvoker5[T1, T2, T3, T4, T5]) Use(handler ...MayHandler) *MayInvoker5[T1, T2, T3, T4, T5]
- type MayInvoker6
- func (h MayInvoker6) CollectAsError() error
- func (h MayInvoker6) CollectAsErrors() []error
- func (h MayInvoker6) HandleErrors(handler func(errs []error))
- func (h MayInvoker6) HandleErrorsWithReturn(handler func(errs []error) error) error
- func (f *MayInvoker6[T1, T2, T3, T4, T5, T6]) Invoke(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, err any, messageArgs ...any) (T1, T2, T3, T4, T5, T6)
- func (f *MayInvoker6[T1, T2, T3, T4, T5, T6]) Use(handler ...MayHandler) *MayInvoker6[T1, T2, T3, T4, T5, T6]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Invoke ¶
Invoke invokes the callback function and enables to control the context of the callback function with 1 return value.
Example ¶
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*500)
defer cancel()
str, err := Invoke(ctx, func() (int, error) {
time.Sleep(time.Second)
return 0, nil
})
fmt.Println(str, err)
Output: 0 context deadline exceeded
func Invoke3 ¶
func Invoke3[R1 any, R2 any, R3 any](ctx context.Context, fn func() (R1, R2, R3, error)) (R1, R2, R3, error)
Invoke3 has the same behavior as Invoke but with 3 return values.
func Invoke4 ¶
func Invoke4[R1 any, R2 any, R3 any, R4 any](ctx context.Context, fn func() (R1, R2, R3, R4, error)) (R1, R2, R3, R4, error)
Invoke4 has the same behavior as Invoke but with 4 return values.
func Invoke5 ¶
func Invoke5[R1 any, R2 any, R3 any, R4 any, R5 any](ctx context.Context, fn func() (R1, R2, R3, R4, R5, error)) (R1, R2, R3, R4, R5, error)
Invoke5 has the same behavior as Invoke but with 5 return values.
func Invoke6 ¶
func Invoke6[R1 any, R2 any, R3 any, R4 any, R5 any, R6 any](ctx context.Context, fn func() (R1, R2, R3, R4, R5, R6, error)) (R1, R2, R3, R4, R5, R6, error)
Invoke6 has the same behavior as Invoke but with 6 return values.
func InvokeWith ¶ added in v1.2.0
func InvokeWith[R1 any](fn func() (R1, error), opts ...CallInvokeWithOption) (R1, error)
InvokeWith invokes the callback function with the CallInvokeWithOption passed in and set for context.Background() as parent context and enables to control the context of the callback function with 1 return value and an error.
Example ¶
str, err := InvokeWith(func() (int, error) {
time.Sleep(time.Second)
return 0, nil
}, WithContextTimeout(time.Millisecond*500))
fmt.Println(str, err)
Output: 0 context deadline exceeded
func InvokeWith0 ¶ added in v1.2.0
func InvokeWith0(fn func() error, opts ...CallInvokeWithOption) error
InvokeWith0 has the same behavior as InvokeWith but without return value.
func InvokeWith1 ¶ added in v1.2.0
func InvokeWith1[R1 any](fn func() (R1, error), opts ...CallInvokeWithOption) (R1, error)
InvokeWith1 is an alias of InvokeWith.
func InvokeWith2 ¶ added in v1.2.0
func InvokeWith2[R1 any, R2 any](fn func() (R1, R2, error), opts ...CallInvokeWithOption) (R1, R2, error)
InvokeWith2 has the same behavior as InvokeWith but with 2 return values.
func InvokeWith3 ¶ added in v1.2.0
func InvokeWith3[R1 any, R2 any, R3 any](fn func() (R1, R2, R3, error), opts ...CallInvokeWithOption) (R1, R2, R3, error)
InvokeWith3 has the same behavior as InvokeWith but with 3 return values.
func InvokeWith4 ¶ added in v1.2.0
func InvokeWith4[R1 any, R2 any, R3 any, R4 any](fn func() (R1, R2, R3, R4, error), opts ...CallInvokeWithOption) (R1, R2, R3, R4, error)
InvokeWith4 has the same behavior as InvokeWith but with 4 return values.
func InvokeWith5 ¶ added in v1.2.0
func InvokeWith5[R1 any, R2 any, R3 any, R4 any, R5 any](fn func() (R1, R2, R3, R4, R5, error), opts ...CallInvokeWithOption) (R1, R2, R3, R4, R5, error)
InvokeWith5 has the same behavior as InvokeWith but with 5 return values.
func InvokeWith6 ¶ added in v1.2.0
func InvokeWith6[R1 any, R2 any, R3 any, R4 any, R5 any, R6 any](fn func() (R1, R2, R3, R4, R5, R6, error), opts ...CallInvokeWithOption) (R1, R2, R3, R4, R5, R6, error)
InvokeWith6 has the same behavior as InvokeWith but with 6 return values.
func InvokeWithTimeout ¶ added in v1.2.0
InvokeWithTimeout invokes the callback function with the timeout passed in and set for context.Background() as parent context with context.WithTimeout(...) and enables to control the timeout context of the callback function with 1 return value and an error.
Example ¶
str, err := InvokeWithTimeout(func() (int, error) {
time.Sleep(time.Second)
return 0, nil
}, time.Millisecond*500)
fmt.Println(str, err)
Output: 0 context deadline exceeded
func InvokeWithTimeout0 ¶ added in v1.2.0
InvokeWithTimeout0 has the same behavior as InvokeWithTimeout but without return value.
func InvokeWithTimeout1 ¶ added in v1.2.0
InvokeWithTimeout1 is an alias of InvokeWithTimeout.
func InvokeWithTimeout2 ¶ added in v1.2.0
func InvokeWithTimeout2[R1 any, R2 any](fn func() (R1, R2, error), timeout time.Duration) (R1, R2, error)
InvokeWithTimeout2 has the same behavior as InvokeWithTimeout but with 2 return values.
func InvokeWithTimeout3 ¶ added in v1.2.0
func InvokeWithTimeout3[R1 any, R2 any, R3 any](fn func() (R1, R2, R3, error), timeout time.Duration) (R1, R2, R3, error)
InvokeWithTimeout3 has the same behavior as InvokeWithTimeout but with 3 return values.
func InvokeWithTimeout4 ¶ added in v1.2.0
func InvokeWithTimeout4[R1 any, R2 any, R3 any, R4 any](fn func() (R1, R2, R3, R4, error), timeout time.Duration) (R1, R2, R3, R4, error)
InvokeWithTimeout4 has the same behavior as InvokeWithTimeout but with 4 return values.
func InvokeWithTimeout5 ¶ added in v1.2.0
func InvokeWithTimeout5[R1 any, R2 any, R3 any, R4 any, R5 any](fn func() (R1, R2, R3, R4, R5, error), timeout time.Duration) (R1, R2, R3, R4, R5, error)
InvokeWithTimeout5 has the same behavior as InvokeWithTimeout but with 5 return values.
func InvokeWithTimeout6 ¶ added in v1.2.0
func InvokeWithTimeout6[R1 any, R2 any, R3 any, R4 any, R5 any, R6 any](fn func() (R1, R2, R3, R4, R5, R6, error), timeout time.Duration) (R1, R2, R3, R4, R5, R6, error)
InvokeWithTimeout6 has the same behavior as InvokeWithTimeout but with 6 return values.
func May ¶
May is a helper that wraps a call to a callback function and then filters out the error from the result and only returns the value. If the error is not nil, it will be handled by handlers registered by SetMayHandlers(...), or be logged by default logging handler.
Example ¶
funcWithError := func() (int, error) {
return 0, errors.New("something went wrong")
}
funcWithNilErr := func() (int, error) {
return 42, nil
}
str := May(funcWithError())
str2 := May(funcWithNilErr())
fmt.Println(str)
fmt.Println(str2)
Output: 0 42
func May4 ¶
func May4[T1 any, T2 any, T3 any, T4 any](t1 T1, t2 T2, t3 T3, t4 T4, err any, messageArgs ...any) (T1, T2, T3, T4)
May4 has the same behavior as May, but callback returns 4 variables.
func May5 ¶
func May5[T1 any, T2 any, T3 any, T4 any, T5 any](t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, err any, messageArgs ...any) (T1, T2, T3, T4, T5)
May5 has the same behavior as May, but callback returns 5 variables.
func May6 ¶
func May6[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any](t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, err any, messageArgs ...any) (T1, T2, T3, T4, T5, T6)
May6 has the same behavior as May, but callback returns 6 variables.
func SetHandlers ¶
func SetHandlers(handler ...MayHandler)
SetHandlers sets the global handlers for May and May* functions.
NOTICE: This function will replace all the global existing handlers on package fo level.
func SetLoggers ¶
func SetLoggers(logger ...Logger)
SetLoggers sets the global loggers for May and May* functions.
NOTICE: This function will replace all the global existing handlers on package fo level.
Types ¶
type CallInvokeWithOption ¶ added in v1.2.0
type CallInvokeWithOption struct {
// contains filtered or unexported fields
}
func WithContextTimeout ¶ added in v1.2.0
func WithContextTimeout(timeout time.Duration) CallInvokeWithOption
type MayHandler ¶
MayHandler is a function that handles the error from May and May* functions.
func WithLogFuncHandler ¶
func WithLogFuncHandler(logFunc func(...any)) MayHandler
WithLogFuncHandler returns a MayHandler that logs the error with the given logFunc which accepts variadic arguments.
func WithLoggerHandler ¶
func WithLoggerHandler(l Logger) MayHandler
WithLoggerHandler returns a MayHandler that logs the error with the given logger.
func WithZapLoggerFuncHandler ¶ added in v1.4.0
func WithZapLoggerFuncHandler(logFunc func(message string, fields ...zap.Field)) MayHandler
WithZapLoggerHandler returns a MayHandler that logs the error with the given zap logger. It will automatically assert whether the passed args are zap.Field and convert the messageArgs zap.Field if it is not a string with error_field prefix.
Usage:
may := fo.NewMay()
may.Use(fo.WithZapLoggerHandler(zapLogger))
may.Invoke(os.Open("./test_file.json"), "failed to open file", zap.String("file", "test_file.json"))
type MayInvoker ¶
type MayInvoker[T any] struct { // contains filtered or unexported fields }
MayInvoker is a helper instance that enables to invoke a call to a callback function and then filters out the error from the result and only returns the value. If the error is not nil, it will be collected to mayHandlers and then handled by handlers registered by Use(...)
func NewMay ¶
func NewMay[T any]() *MayInvoker[T]
NewMay creates a helper instance that enables to invoke a call to a callback function and then filters out the error from the result and only returns the value. If the error is not nil, it will be collected to mayHandlers and then handled by handlers registered by Use(...)
Example ¶
errFn := func() (string, error) {
return "", errors.New("an error")
}
may := NewMay[string]()
res1 := may.Invoke(errFn())
errNilFn := func() (string, error) {
return "success", nil
}
res2 := may.Invoke(errNilFn())
fmt.Println(strings.Join([]string{res1, res2}, ","))
Output: ,success
func (MayInvoker) CollectAsError ¶ added in v1.1.0
func (h MayInvoker) CollectAsError() error
CollectAsError collects error from the invoked result from MayInvoker for post error handling.
The error can be extracted with
multierr.Errors().
func (MayInvoker) CollectAsErrors ¶ added in v1.1.0
func (h MayInvoker) CollectAsErrors() []error
CollectAsErrors collects errors from the invoked result from MayInvoker for post error handling.
The errors can be combined with
multierr.Combine().
func (MayInvoker) HandleErrors ¶ added in v1.1.0
func (h MayInvoker) HandleErrors(handler func(errs []error))
HandleErrors executes the handler with the collected error from MayInvoker.
Example ¶
// Such scenario is useful when you want to handle errors in a defer statement
funcWithHandlingErrorsInDefer := func() (num int, num2 int, err error) {
may := NewMay[int]()
defer func() {
// Using defer to handle errors and assign the err into named return value
err = may.HandleErrorsWithReturn(func(errs []error) error {
return fmt.Errorf("error occurred: %w", multierr.Combine(errs...))
})
}()
funcWithErr := func() (int, error) {
return 0, errors.New("something went wrong")
}
funcWithNilErr := func() (int, error) {
return 42, nil
}
num = may.Invoke(funcWithErr())
num2 = may.Invoke(funcWithNilErr())
return num, num2, nil
}
num, num2, err := funcWithHandlingErrorsInDefer()
fmt.Println(num, num2, err)
// Such scenario is useful when you want to handle errors in a separated function
funcWithHandlingErrorsWithReformatting := func() (num int, num2 int, err error) { //nolint:unparam
may := NewMay[int]()
funcWithErr := func() (int, error) {
return 0, errors.New("something went wrong")
}
funcWithNilErr := func() (int, error) {
return 42, nil
}
num = may.Invoke(funcWithErr())
num2 = may.Invoke(funcWithNilErr())
may.HandleErrors(func(errs []error) {
fmt.Println("encountered errors:", errs)
})
return num, num2, nil
}
num, num2, err = funcWithHandlingErrorsWithReformatting()
fmt.Println(num, num2, err)
Output: 0 42 error occurred: something went wrong encountered errors: [something went wrong] 0 42 <nil>
func (MayInvoker) HandleErrorsWithReturn ¶ added in v1.1.0
HandleErrorsWithReturn executes the handler with the collected error from MayInvoker, and returns the error that handled by the handler.
Example ¶
criticalErr := errors.New("critical error")
// Such scenario is useful when you want to handle errors and then return a new one after
// reformatting, grouping, logging the errors or etc.
funcWithHandlingErrors := func() (num int, num2 int, err error) {
may := NewMay[int]()
funcWithErr := func() (int, error) {
return 0, criticalErr
}
funcWithNilErr := func() (int, error) {
return 42, nil
}
num = may.Invoke(funcWithErr())
num2 = may.Invoke(funcWithNilErr())
err = may.HandleErrorsWithReturn(func(errs []error) error {
for _, e := range errs {
if errors.Is(e, criticalErr) {
return fmt.Errorf("critical error occurred: %w", e)
}
}
return fmt.Errorf("error occurred: %w", multierr.Combine(errs...))
})
return num, num2, err
}
num, num2, err := funcWithHandlingErrors()
fmt.Println(num, num2, err)
Output: 0 42 critical error occurred: critical error
func (*MayInvoker[T]) Invoke ¶
func (f *MayInvoker[T]) Invoke(t1 T, err any, messageArgs ...any) T
Invoke invokes the callback function and filters out the error from the result and only returns the value. If the error is not nil, it will be collected and handled by handlers registered by Use(...)
func (*MayInvoker[T]) Use ¶
func (f *MayInvoker[T]) Use(handler ...MayHandler) *MayInvoker[T]
Use registers the handlers.
Example ¶
var outErr error
handler := func(err error, v ...any) {
outErr = err
}
may := NewMay[string]().Use(handler)
res := may.Invoke(func() (string, error) {
return "", errors.New("an error")
}())
fmt.Println(strings.Join([]string{res, outErr.Error()}, ","))
Output: ,an error
type MayInvoker0 ¶
type MayInvoker0 struct {
// contains filtered or unexported fields
}
MayInvoker0 is a helper instance that behaves like MayInvoker , but it allows to invoke a callback function that returns no value.
func NewMay0 ¶
func NewMay0() *MayInvoker0
NewMay0 creates a helper instance behaves like MayInvoker, but it allows to invoke a callback function that returns no value.
func (MayInvoker0) CollectAsError ¶ added in v1.1.0
func (h MayInvoker0) CollectAsError() error
CollectAsError collects error from the invoked result from MayInvoker for post error handling.
The error can be extracted with
multierr.Errors().
func (MayInvoker0) CollectAsErrors ¶ added in v1.1.0
func (h MayInvoker0) CollectAsErrors() []error
CollectAsErrors collects errors from the invoked result from MayInvoker for post error handling.
The errors can be combined with
multierr.Combine().
func (MayInvoker0) HandleErrors ¶ added in v1.1.0
func (h MayInvoker0) HandleErrors(handler func(errs []error))
HandleErrors executes the handler with the collected error from MayInvoker.
func (MayInvoker0) HandleErrorsWithReturn ¶ added in v1.1.0
HandleErrorsWithReturn executes the handler with the collected error from MayInvoker, and returns the error that handled by the handler.
func (*MayInvoker0) Invoke ¶
func (f *MayInvoker0) Invoke(anyErr any, messageArgs ...any)
Invoke invokes the callback function and filters out the error from the result and only returns the value. If the error is not nil, it will be collected and handled by handlers registered by Use(...)
func (*MayInvoker0) Use ¶
func (f *MayInvoker0) Use(handler ...MayHandler) *MayInvoker0
Use registers the handlers.
type MayInvoker2 ¶
MayInvoker2 is a helper instance behaves like MayInvoker, but it allows to invoke a callback function that returns 2 values.
func NewMay2 ¶
func NewMay2[T1 any, T2 any]() *MayInvoker2[T1, T2]
NewMay2 creates a helper instance behaves like MayInvoker, but it allows to invoke a callback function that returns 2 values.
func (MayInvoker2) CollectAsError ¶ added in v1.1.0
func (h MayInvoker2) CollectAsError() error
CollectAsError collects error from the invoked result from MayInvoker for post error handling.
The error can be extracted with
multierr.Errors().
func (MayInvoker2) CollectAsErrors ¶ added in v1.1.0
func (h MayInvoker2) CollectAsErrors() []error
CollectAsErrors collects errors from the invoked result from MayInvoker for post error handling.
The errors can be combined with
multierr.Combine().
func (MayInvoker2) HandleErrors ¶ added in v1.1.0
func (h MayInvoker2) HandleErrors(handler func(errs []error))
HandleErrors executes the handler with the collected error from MayInvoker.
func (MayInvoker2) HandleErrorsWithReturn ¶ added in v1.1.0
HandleErrorsWithReturn executes the handler with the collected error from MayInvoker, and returns the error that handled by the handler.
func (*MayInvoker2[T1, T2]) Invoke ¶
func (f *MayInvoker2[T1, T2]) Invoke(t1 T1, t2 T2, err any, messageArgs ...any) (T1, T2)
Invoke invokes the callback function and filters out the error from the result and only returns the value. If the error is not nil, it will be collected and handled by handlers registered by Use(...)
func (*MayInvoker2[T1, T2]) Use ¶
func (f *MayInvoker2[T1, T2]) Use(handler ...MayHandler) *MayInvoker2[T1, T2]
Use registers the handlers.
type MayInvoker3 ¶
MayInvoker3 is a helper instance behaves like MayInvoker, but it allows to invoke a callback function that returns 3 values.
func NewMay3 ¶
func NewMay3[T1 any, T2 any, T3 any]() *MayInvoker3[T1, T2, T3]
NewMay3 creates a helper instance behaves like MayInvoker, but it allows to invoke a callback function that returns 3 values.
func (MayInvoker3) CollectAsError ¶ added in v1.1.0
func (h MayInvoker3) CollectAsError() error
CollectAsError collects error from the invoked result from MayInvoker for post error handling.
The error can be extracted with
multierr.Errors().
func (MayInvoker3) CollectAsErrors ¶ added in v1.1.0
func (h MayInvoker3) CollectAsErrors() []error
CollectAsErrors collects errors from the invoked result from MayInvoker for post error handling.
The errors can be combined with
multierr.Combine().
func (MayInvoker3) HandleErrors ¶ added in v1.1.0
func (h MayInvoker3) HandleErrors(handler func(errs []error))
HandleErrors executes the handler with the collected error from MayInvoker.
func (MayInvoker3) HandleErrorsWithReturn ¶ added in v1.1.0
HandleErrorsWithReturn executes the handler with the collected error from MayInvoker, and returns the error that handled by the handler.
func (*MayInvoker3[T1, T2, T3]) Invoke ¶
func (f *MayInvoker3[T1, T2, T3]) Invoke(t1 T1, t2 T2, t3 T3, err any, messageArgs ...any) (T1, T2, T3)
Invoke invokes the callback function and filters out the error from the result and only returns the value. If the error is not nil, it will be collected and handled by handlers registered by Use(...)
func (*MayInvoker3[T1, T2, T3]) Use ¶
func (f *MayInvoker3[T1, T2, T3]) Use(handler ...MayHandler) *MayInvoker3[T1, T2, T3]
Use registers the handlers.
type MayInvoker4 ¶
type MayInvoker4[T1 any, T2 any, T3 any, T4 any] struct { // contains filtered or unexported fields }
MayInvoker4 is a helper instance behaves like MayInvoker, but it allows to invoke a callback function that returns 4 values.
func NewMay4 ¶
func NewMay4[T1 any, T2 any, T3 any, T4 any]() *MayInvoker4[T1, T2, T3, T4]
NewMay4 creates a helper instance behaves like MayInvoker, but it allows to invoke a callback function that returns 4 values.
func (MayInvoker4) CollectAsError ¶ added in v1.1.0
func (h MayInvoker4) CollectAsError() error
CollectAsError collects error from the invoked result from MayInvoker for post error handling.
The error can be extracted with
multierr.Errors().
func (MayInvoker4) CollectAsErrors ¶ added in v1.1.0
func (h MayInvoker4) CollectAsErrors() []error
CollectAsErrors collects errors from the invoked result from MayInvoker for post error handling.
The errors can be combined with
multierr.Combine().
func (MayInvoker4) HandleErrors ¶ added in v1.1.0
func (h MayInvoker4) HandleErrors(handler func(errs []error))
HandleErrors executes the handler with the collected error from MayInvoker.
func (MayInvoker4) HandleErrorsWithReturn ¶ added in v1.1.0
HandleErrorsWithReturn executes the handler with the collected error from MayInvoker, and returns the error that handled by the handler.
func (*MayInvoker4[T1, T2, T3, T4]) Invoke ¶
func (f *MayInvoker4[T1, T2, T3, T4]) Invoke(t1 T1, t2 T2, t3 T3, t4 T4, err any, messageArgs ...any) (T1, T2, T3, T4)
Invoke invokes the callback function and filters out the error from the result and only returns the value. If the error is not nil, it will be collected and handled by handlers registered by Use(...)
func (*MayInvoker4[T1, T2, T3, T4]) Use ¶
func (f *MayInvoker4[T1, T2, T3, T4]) Use(handler ...MayHandler) *MayInvoker4[T1, T2, T3, T4]
Use registers the handlers.
type MayInvoker5 ¶
type MayInvoker5[T1 any, T2 any, T3 any, T4 any, T5 any] struct { // contains filtered or unexported fields }
MayInvoker5 is a helper instance behaves like MayInvoker, but it allows to invoke a callback function that returns 5 values.
func NewMay5 ¶
NewMay5 creates a helper instance behaves like MayInvoker, but it allows to invoke a callback function that returns 5 values.
func (MayInvoker5) CollectAsError ¶ added in v1.1.0
func (h MayInvoker5) CollectAsError() error
CollectAsError collects error from the invoked result from MayInvoker for post error handling.
The error can be extracted with
multierr.Errors().
func (MayInvoker5) CollectAsErrors ¶ added in v1.1.0
func (h MayInvoker5) CollectAsErrors() []error
CollectAsErrors collects errors from the invoked result from MayInvoker for post error handling.
The errors can be combined with
multierr.Combine().
func (MayInvoker5) HandleErrors ¶ added in v1.1.0
func (h MayInvoker5) HandleErrors(handler func(errs []error))
HandleErrors executes the handler with the collected error from MayInvoker.
func (MayInvoker5) HandleErrorsWithReturn ¶ added in v1.1.0
HandleErrorsWithReturn executes the handler with the collected error from MayInvoker, and returns the error that handled by the handler.
func (*MayInvoker5[T1, T2, T3, T4, T5]) Invoke ¶
func (f *MayInvoker5[T1, T2, T3, T4, T5]) Invoke(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, err any, messageArgs ...any) (T1, T2, T3, T4, T5)
Invoke invokes the callback function and filters out the error from the result and only returns the value. If the error is not nil, it will be collected and handled by handlers registered by Use(...)
func (*MayInvoker5[T1, T2, T3, T4, T5]) Use ¶
func (f *MayInvoker5[T1, T2, T3, T4, T5]) Use(handler ...MayHandler) *MayInvoker5[T1, T2, T3, T4, T5]
Use registers the handlers.
type MayInvoker6 ¶
type MayInvoker6[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any] struct { // contains filtered or unexported fields }
MayInvoker6 is a helper instance behaves like MayInvoker, but it allows to invoke a callback function that returns 6 values.
func NewMay6 ¶
NewMay6 creates a helper instance behaves like MayInvoker, but it allows to invoke a callback function that returns 6 values.
func (MayInvoker6) CollectAsError ¶ added in v1.1.0
func (h MayInvoker6) CollectAsError() error
CollectAsError collects error from the invoked result from MayInvoker for post error handling.
The error can be extracted with
multierr.Errors().
func (MayInvoker6) CollectAsErrors ¶ added in v1.1.0
func (h MayInvoker6) CollectAsErrors() []error
CollectAsErrors collects errors from the invoked result from MayInvoker for post error handling.
The errors can be combined with
multierr.Combine().
func (MayInvoker6) HandleErrors ¶ added in v1.1.0
func (h MayInvoker6) HandleErrors(handler func(errs []error))
HandleErrors executes the handler with the collected error from MayInvoker.
func (MayInvoker6) HandleErrorsWithReturn ¶ added in v1.1.0
HandleErrorsWithReturn executes the handler with the collected error from MayInvoker, and returns the error that handled by the handler.
func (*MayInvoker6[T1, T2, T3, T4, T5, T6]) Invoke ¶
func (f *MayInvoker6[T1, T2, T3, T4, T5, T6]) Invoke(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, err any, messageArgs ...any) (T1, T2, T3, T4, T5, T6)
Invoke invokes the callback function and filters out the error from the result and only returns the value. If the error is not nil, it will be collected and handled by handlers registered by Use(...)
func (*MayInvoker6[T1, T2, T3, T4, T5, T6]) Use ¶
func (f *MayInvoker6[T1, T2, T3, T4, T5, T6]) Use(handler ...MayHandler) *MayInvoker6[T1, T2, T3, T4, T5, T6]
Use registers the handlers.