reflect

package
v0.0.32 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: MPL-2.0 Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FuncEqual

func FuncEqual(fn1, fn2 any) bool

func GetFuncName

func GetFuncName(fn any) string

GetFuncName 从函数实例获取函数名

func GetFuncSignature

func GetFuncSignature(fn any) string

GetFuncSignature 获取函数签名信息

func GetStructName

func GetStructName(obj any) string

GetStructName 获取结构名

func GetVarName

func GetVarName(v any) string

GetVarName 获取变量名

func Indirect added in v0.0.22

func Indirect(a any) any

Indirect returns the value, after dereferencing as many times as necessary to reach the base type (or nil).

func IsAssignableStruct added in v0.0.17

func IsAssignableStruct(obj any) bool

IsAssignableStruct 是否是可赋值的结构指针类型

func MatchReceiverMethods

func MatchReceiverMethods(receiver any, matchFn any) map[string]any

MatchReceiverMethods 匹配receiver的所有methods中与matchFn签名参数类似的方法

func StructSet

func StructSet(obj any, nilField any, val any) error

StructSet 通过反射给结构体obj的nilField类型匹配的field赋值val

Types

type Utils

type Utils interface {
	GetFuncName(fn any) string                                     //从函数实例获取函数名
	GetStructName(obj any) string                                  // 从实例获取结构名
	GetVarName(v any) string                                       // 获取变量名
	StructSet(obj any, nilField any, val any) error                // 给结构体设置field类型的值
	MatchReceiverMethods(receiver any, matchFn any) map[string]any // 匹配receiver的所有methods中与matchFn签名参数类似的方法
	GetFuncSignature(fn any) string                                // 获取函数签名信息
	InspectValue(v any) Value                                      // 检索Value的信息
	FuncEqual(fn1, fn2 any) bool                                   // 函数是否相等
	IsAssignableStruct(obj any) bool                               // 是否是可赋值的结构指针类型
	Indirect(a any) any                                            // 通过尽可能的解引用获取底层的类型
}

type Value

type Value struct {
	Name      string
	IsPointer bool
	Kind      string
	Items     []ValueItem
}

func InspectValue

func InspectValue(v any) *Value

type ValueItem

type ValueItem struct {
	Name  string
	Kind  string
	Value any
}

func GetSliceItems

func GetSliceItems(sv reflect.Value) []ValueItem

func GetStructFields

func GetStructFields(st reflect.Type, sv reflect.Value) []ValueItem

Jump to

Keyboard shortcuts

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