dynamic

package
v1.39.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2022 License: AGPL-3.0 Imports: 9 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCanNotIterateNilPointer = errors.New("can not iterate struct on a nil pointer")

Functions

func CallMatch

func CallMatch(f interface{}, objects ...interface{}) ([]reflect.Value, error)

CallMatch calls the function with the matched argument automatically you can define multiple parameter factory function to inject the return value as the function argument. e.g.,

CallMatch(targetFunction, 1, 10, true, func() *ParamType { .... })

func CallStructFieldsMethod

func CallStructFieldsMethod(m interface{}, method string, args ...interface{}) error

CallStructFieldsMethod iterates field from the given struct object check if the field object implements the interface, if it's implemented, then we call a specific method

func CanInt added in v1.39.2

func CanInt(v reflect.Value) bool

For backward compatibility of reflect.Value.CanInt in go1.17

func HasField

func HasField(rs reflect.Value, fieldName string) (field reflect.Value, ok bool)

func InheritStructValues

func InheritStructValues(dst, src interface{})

InheritStructValues merges the field value from the source struct to the dest struct. Only fields with the same type and the same name will be updated.

func InjectField

func InjectField(rs reflect.Value, fieldName string, obj interface{}, pointerOnly bool) error

func IterateFields

func IterateFields(obj interface{}, cb func(ft reflect.StructField, fv reflect.Value) error) error

func IterateFieldsByTag

func IterateFieldsByTag(obj interface{}, tagName string, cb StructFieldIterator) error

func LookupSymbolField

func LookupSymbolField(rs reflect.Value) (string, bool)

func ParseStructAndInject

func ParseStructAndInject(f interface{}, objects ...interface{}) error

ParseStructAndInject parses the struct fields and injects the objects into the corresponding fields by its type. if the given object is a reference of an object, the type of the target field MUST BE a pointer field. if the given object is a struct value, the type of the target field CAN BE a pointer field or a struct value field.

func Test_injectField

func Test_injectField(t *testing.T)

func Test_parseStructAndInject

func Test_parseStructAndInject(t *testing.T)

func ToReflectValues

func ToReflectValues(args ...interface{}) (values []reflect.Value)

ToReflectValues convert the go objects into reflect.Value slice

Types

type StructFieldIterator

type StructFieldIterator func(tag string, ft reflect.StructField, fv reflect.Value) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL