dynamic

package
v1.60.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: AGPL-3.0 Imports: 15 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 CallID added in v1.40.0

func CallID(obj interface{}) string

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 DefaultWhiteList added in v1.40.0

func DefaultWhiteList() []string

func FieldByIndexErr added in v1.42.0

func FieldByIndexErr(v reflect.Value, index []int) (reflect.Value, error)

Modified from golang 1.19.1 reflect to eliminate all possible panic

func GetModifiableField added in v1.41.0

func GetModifiableField(val reflect.Value, name string) (reflect.Value, bool)

func GetModifiableFields added in v1.41.0

func GetModifiableFields(val reflect.Value, callback func(tagName, name string))

Used by bbgo/interact_modify.go

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(target interface{}, 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, children bool, cb StructFieldIterator) error

func LookupSymbolField

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

func ParamDump added in v1.42.0

func ParamDump(s interface{}, f io.Writer, seriesLength ...int)

@param s: strategy object @param f: io.Writer used for writing the strategy dump @param seriesLength: if exist, the first value will be chosen to be the length of data from series to be printed out

default to 1 when not exist or the value is invalid

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 PrintConfig added in v1.40.0

func PrintConfig(s interface{}, f io.Writer, style *table.Style, withColor bool, whiteLists ...string)

@param s: strategy object @param f: io.Writer used for writing the config dump @param style: pretty print table style. Use NewDefaultTableStyle() to get default one. @param withColor: whether to print with color @param whiteLists: fields to be printed out from embedded struct (1st layer only)

func ToReflectValues

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

ToReflectValues convert the go objects into reflect.Value slice

Types

type InstanceIDProvider added in v1.40.0

type InstanceIDProvider interface {
	InstanceID() string
}

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