Documentation
¶
Index ¶
- Variables
- func CastFunc[OUT Function](fn any, opts ...func(*FuncConfig)) (OUT, error)
- func ConvertToType(value reflect.Value, targetType reflect.Type) (reflect.Value, error)
- func IsZero(value interface{}) bool
- func Method[T Function](obj interface{}, name string, opts ...func(*FuncConfig)) (n T, err error)
- func RCastFunc(out reflect.Type, fn any, opts ...func(*FuncConfig)) (reflect.Value, error)
- func RConvert(v *reflect.Value, t reflect.Type) (*reflect.Value, bool)
- func RSet(src, dst *reflect.Value, convert bool) bool
- func WrapWithContext(ctx context.Context) func(*FuncConfig)
- type Func
- type FuncConfig
- type Function
Constants ¶
This section is empty.
Variables ¶
var ( ErrTypeMismatch = errors.New("type mismatch") ErrNotFunc = errors.New("fn must be a function") ErrArgCount = errors.New("argument count mismatch") ErrReturnCount = errors.New("return count mismatch") ErrNilObject = errors.New("object is nil") ErrMethodNotFound = errors.New("method not found") )
Functions ¶
func ConvertToType ¶
func Method ¶
func Method[T Function](obj interface{}, name string, opts ...func(*FuncConfig)) (n T, err error)
Method retrieves a method from an object.
The generic type parameter must be the type of the method.
func RConvert ¶
RConvert converts a reflect.Value to a different type.
If the value is not convertible to the type, the original value is returned.
If the pointer of `v` is invalid, a new value of type `t` is created, and the pointer is set to it, then the pointer is returned.
func RSet ¶
RSet sets a value from one reflect.Value to another.
If the destination value is not settable, this function will return false.
If the source value is not immediately assignable to the destination value, and the convert parameter is true, the source value will be converted to the destination value's type.
If the source value is not immediately assignable to the destination value, and the convert parameter is false, this function will return false.
func WrapWithContext ¶
func WrapWithContext(ctx context.Context) func(*FuncConfig)
Types ¶
type Func ¶
type FuncConfig ¶
type FuncConfig struct {
// wrappers are applied before any validation occurs
// this /could/ be used to set default values for parameters
// such as context.Context, http.Request, etc.
Wrappers []func(src reflect.Value, srcTyp reflect.Type, dst reflect.Type) (newSrc reflect.Value)
// decorators are applied after validation occurs
// you can use decorators to execute code before and after
// the function is called. it is also possible
// to modify the input and output parameters.
Decorators []func(fn reflectFunc) reflectFunc
}