dynamic

package
v0.0.0-...-cb4139d Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2023 License: AGPL-3.0 Imports: 18 Imported by: 0

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

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

func CanInt(v reflect.Value) bool

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

func DefaultWhiteList

func DefaultWhiteList() []string

func FieldByIndexErr

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

Modified from golang 1.19.1 reflect to eliminate all possible panic

func GetModifiableField

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

func GetModifiableFields

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(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 ParamDump

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

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 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 InstanceIDProvider

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