reflectx

package
v1.5.27 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForEachField

func ForEachField(o interface{}, excludePrivateField bool, f FieldAcceptor) error

func ForEachFieldV2

func ForEachFieldV2(t reflect.Type, v reflect.Value, excludePrivateField bool, f FieldAcceptor) error

func Id added in v1.2.0

func Id(c any) string

func Interfaces2Values

func Interfaces2Values(o []any) []reflect.Value

func IsImplement

func IsImplement(instance any, _interface any) bool

func IsTypeImplement

func IsTypeImplement(typ reflect.Type, _interface any) bool

func New added in v1.1.0

func New(t reflect.Type) reflect.Value

func Set added in v1.1.0

func Set(dst, src reflect.Value)

func SetAnyValueFromString added in v1.5.0

func SetAnyValueFromString(t reflect.Type, value reflect.Value, val string, itps ...Interceptor) error

func SetValue added in v1.5.0

func SetValue(value reflect.Value, setter func(a any) error) error

func TryCallMethod

func TryCallMethod(b interface{}, methodName string, args ...any) []reflect.Value

func TypeId added in v1.2.0

func TypeId(p reflect.Type) string

func Values2Interfaces

func Values2Interfaces(values []reflect.Value) []any

func WalkField

func WalkField(o interface{}, f FieldWalkAcceptor) error

WalkField walk the struct field with DFS, and break when meeting the nil pointer value, can be checked by value.Elem().InValid()

func WalkFieldV2

func WalkFieldV2(t reflect.Type, v reflect.Value, f FieldWalkAcceptor) error

func ZeroValue added in v1.5.1

func ZeroValue(p reflect.Type) any

Types

type FieldAcceptor

type FieldAcceptor func(field reflect.StructField, value reflect.Value) error

type FieldWalkAcceptor added in v1.2.0

type FieldWalkAcceptor func(parent *Node, field reflect.StructField, value reflect.Value) error

type Interceptor added in v1.5.0

type Interceptor map[reflect.Kind]SetValueHandler

type Node added in v1.2.0

type Node struct {
	Parent *Node
	Field  reflect.StructField
	Value  reflect.Value
}

func (*Node) Path added in v1.2.0

func (n *Node) Path() []*Node

type SetValueHandler added in v1.5.0

type SetValueHandler func(reflect.Type, reflect.Value, string) error
var JsonUnmarshallHandler SetValueHandler = func(r reflect.Type, v reflect.Value, s string) error {
	return SetValue(v, func(a any) error {
		err := json.Unmarshal([]byte(s), a)
		if err != nil {
			return errors.Wrapf(err, "unmarshall json %s to type '%s' failed", s, r.String())
		}
		return nil
	})
}

Jump to

Keyboard shortcuts

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