reflectKit

package
v2.2.27 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetField

func GetField(ptr interface{}, fieldName string) reflect.Value

GetField

PS: 这样获取到的值是不可以修改的,如果要修改name字段,需要用到reflect.NewAt函数,这个函数通过一个类型值的底层地址(指针 p)和类型, 返回指向该值的一个指针,这个返回值是可寻址的,即可通过它直接访问该值。具体的修改是使用reflect.Value.Set函数。

@param fieldName 字段名(属性名),private或public的都可以

func GetNestedField

func GetNestedField(ptr interface{}, fieldNames ...string) (reflect.Value, error)

GetNestedField 获取(层层嵌套的)字段

func SetField

func SetField(ptr interface{}, fieldName string, newFieldValue interface{}) error

SetField

@param fieldName 字段名(属性名),private或public的都可以 @param newFieldValue 字段的新值

Types

This section is empty.

Jump to

Keyboard shortcuts

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