Documentation ¶
Index ¶
- func AnonymousStructFields(obj interface{}) ([]reflect.StructField, error)
- func CallFunc(fn interface{}, args ...interface{}) ([]reflect.Value, error)
- func CallFuncSlice(fn interface{}, args ...interface{}) ([]reflect.Value, error)
- func CallMethod(obj interface{}, method string, params ...interface{}) ([]reflect.Value, error)
- func CallMethodSlice(obj interface{}, method string, params ...interface{}) ([]reflect.Value, error)
- func EmbedField(obj interface{}, fieldPath string) (reflect.Value, error)
- func EmbedFieldKind(obj interface{}, fieldPath string) (reflect.Kind, error)
- func EmbedFieldType(obj interface{}, fieldPath string) (reflect.Type, error)
- func EmbedFieldTypeStr(obj interface{}, fieldPath string) (string, error)
- func EmbedFieldValue(obj interface{}, fieldPath string) (interface{}, error)
- func EmbedStructField(obj interface{}, fieldPath string) (reflect.StructField, error)
- func EmbedStructFieldKind(obj interface{}, fieldPath string) (reflect.Kind, error)
- func EmbedStructFieldType(obj interface{}, fieldPath string) (reflect.Type, error)
- func EmbedStructFieldTypeStr(obj interface{}, fieldPath string) (string, error)
- func Field(obj interface{}, fieldName string) (reflect.Value, error)
- func FieldKind(obj interface{}, fieldName string) (reflect.Kind, error)
- func FieldType(obj interface{}, fieldName string) (reflect.Type, error)
- func FieldTypeStr(obj interface{}, fieldName string) (string, error)
- func FieldValue(obj interface{}, fieldName string) (interface{}, error)
- func Fields(obj interface{}) (map[string]reflect.Value, error)
- func FieldsDeep(obj interface{}) (map[string]reflect.Value, error)
- func GetPkgPath(obj interface{}) string
- func HasStructField(obj interface{}, fieldName string) (bool, error)
- func Implements(obj interface{}, in interface{}) bool
- func NewInstance(obj interface{}) interface{}
- func RangeFields(obj interface{}, f func(string, reflect.StructField, reflect.Value) bool) error
- func RangeFieldsDeep(obj interface{}, f func(string, reflect.StructField, reflect.Value) bool) error
- func RangeStructFields(obj interface{}, f func(int, reflect.StructField) bool) error
- func SelectFields(obj interface{}, f func(string, reflect.StructField, reflect.Value) bool) (map[string]reflect.Value, error)
- func SelectFieldsDeep(obj interface{}, f func(string, reflect.StructField, reflect.Value) bool) (map[string]reflect.Value, error)
- func SelectStructFields(obj interface{}, f func(int, reflect.StructField) bool) ([]reflect.StructField, error)
- func SetEmbedField(obj interface{}, fieldPath string, fieldValue interface{}) error
- func SetField(obj interface{}, fieldName string, fieldValue interface{}) error
- func SetPrivateField(obj interface{}, fieldName string, fieldValue interface{}) error
- func StructField(obj interface{}, fieldName string) (reflect.StructField, error)
- func StructFieldKind(obj interface{}, fieldName string) (reflect.Kind, error)
- func StructFieldTag(obj interface{}, fieldName string) (reflect.StructTag, error)
- func StructFieldTagValue(obj interface{}, fieldName, tagKey string) (string, error)
- func StructFieldType(obj interface{}, fieldName string) (reflect.Type, error)
- func StructFieldTypeStr(obj interface{}, fieldName string) (string, error)
- func StructFields(obj interface{}) ([]reflect.StructField, error)
- func StructFieldsFlatten(obj interface{}) ([]reflect.StructField, error)
- func Type(obj interface{}) reflect.Type
- func TypePenetrateElem(obj interface{}) reflect.Type
- func Value(obj interface{}) reflect.Value
- func ValuePenetrateElem(obj interface{}) reflect.Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnonymousStructFields ¶
func AnonymousStructFields(obj interface{}) ([]reflect.StructField, error)
AnonymousStructFields returns the slice of reflect.StructField of all anonymous fields in obj. The obj can either be a structure or pointer to structure.
func CallFunc ¶
CallFunc invokes a function using reflection and returns the result. It supports variadic arguments and uses the Call method of reflect.Value underneath. Variadic arguments need to be flattened, otherwise should use CallFuncSlice. There is no need to parse errors from the returned []reflect.Value. If the called function's last return value is an error, it will be extracted and returned as the last return value of CallFunc.
func CallFuncSlice ¶
CallFuncSlice has the same functionality as CallFunc, it must have variadic parameters, but it uses the CallSlice method of reflect.Value under the hood. CallSlice calls the variadic function v with the input arguments in, assigning the slice in[len(in)-1] to v's final variadic argument. For example, if len(in) == 3, v.CallSlice(in) represents the Go call v(in[0], in[1], in[2]...).
func CallMethod ¶
CallMethod calls the method `method` of the `obj` object and returns the result, supporting variadic parameters. The `obj` object must be a struct or a struct pointer. It internally uses CallFunc, see CallFunc for more details.
func CallMethodSlice ¶
func CallMethodSlice(obj interface{}, method string, params ...interface{}) ([]reflect.Value, error)
CallMethodSlice has the same functionality as CallMethod, and it uses CallFuncSlice as its underlying implementation. For more details, refer to the CallFuncSlice documentation.
func EmbedField ¶
EmbedField returns the reflect.Value of a field in the nested structure of obj based on the specified fieldPath. The obj can either be a structure or a pointer to a structure.
func EmbedFieldKind ¶
EmbedFieldKind returns the reflect.Kind of a field in the nested structure of obj based on the specified fieldPath. The obj can either be a structure or a pointer to a structure.
func EmbedFieldType ¶
EmbedFieldType returns the reflect.Type of a field in the nested structure of obj based on the specified fieldPath. The obj can either be a structure or a pointer to a structure.
func EmbedFieldTypeStr ¶
EmbedFieldTypeStr returns the string of the reflect.Type of a field in the nested structure of obj based on the specified fieldPath. The obj can either be a structure or a pointer to a structure.
func EmbedFieldValue ¶
EmbedFieldValue returns the actual value of a field in the nested structure of obj based on the specified fieldPath. The obj can either be a structure or a pointer to a structure.
func EmbedStructField ¶
func EmbedStructField(obj interface{}, fieldPath string) (reflect.StructField, error)
EmbedStructField returns the reflect.Value of a field in the nested structure of obj based on the specified fieldPath. The obj can either be a structure or a pointer to a structure.
func EmbedStructFieldKind ¶
EmbedStructFieldKind returns the reflect.Kind of a field in the nested structure of obj based on the specified fieldPath. The obj can either be a structure or a pointer to a structure.
func EmbedStructFieldType ¶
EmbedStructFieldType returns the reflect.Type of a field in the nested structure of obj based on the specified fieldPath. The obj can either be a structure or a pointer to a structure.
func EmbedStructFieldTypeStr ¶
EmbedStructFieldTypeStr returns the string of the reflect.Type of a field in the nested structure of obj based on the specified fieldPath. The obj can either be a structure or a pointer to a structure.
func Field ¶
Field returns the reflect.Value of the provided obj field. The obj can either be a structure or pointer to structure.
func FieldKind ¶
FieldKind returns the reflect.Kind of the provided obj field. The obj can either be a structure or pointer to structure.
func FieldType ¶
FieldType returns the reflect.Type of the provided obj field. The obj can either be a structure or pointer to structure.
func FieldTypeStr ¶
FieldTypeStr returns the string of reflect.Type of the provided obj field. The obj can either be a structure or pointer to structure.
func FieldValue ¶
FieldValue returns the actual value of the provided obj field. The obj can either be a structure or pointer to structure.
func Fields ¶
Fields returns a map of reflect.Value containing all the fields of the obj, with the field names as keys. The obj can either be a structure or a pointer to a structure.
func FieldsDeep ¶
FieldsDeep traverses the obj deeply, including all nested structures, and returns all fields as reflect.Value in the form of a map, where the key is the path of the field. The obj can either be a structure or pointer to structure.
func GetPkgPath ¶
func GetPkgPath(obj interface{}) string
GetPkgPath returns the package path of obj.
func HasStructField ¶
HasStructField checks if the provided obj struct has field named fieldName. The obj can either be a structure or pointer to structure.
func Implements ¶
func Implements(obj interface{}, in interface{}) bool
Implements returns whether obj implements the given interface in.
func NewInstance ¶
func NewInstance(obj interface{}) interface{}
NewInstance returns a new instance of the same type as the input value. The returned value will contain the zero value of the type. If obj type is a slice, chan, etc. , it will create an instance with the same capacity.
func RangeFields ¶
RangeFields iterates over all fields of obj and calls function f on each field. If function f returns false, the iteration stops. The obj can either be a structure or pointer to structure.
func RangeFieldsDeep ¶
func RangeFieldsDeep(obj interface{}, f func(string, reflect.StructField, reflect.Value) bool) error
RangeFieldsDeep performs a deep traversal of obj and its nested structures, and calls function f on each field. If the function f returns false, the iteration stops. The obj can either be a structure or pointer to structure.
func RangeStructFields ¶
func RangeStructFields(obj interface{}, f func(int, reflect.StructField) bool) error
RangeStructFields iterates over all struct fields of obj and calls function f on each field. If function f returns false, the iteration stops. The obj can either be a structure or pointer to structure.
func SelectFields ¶
func SelectFields(obj interface{}, f func(string, reflect.StructField, reflect.Value) bool) (map[string]reflect.Value, error)
SelectFields has the same functionality as Fields, but only the fields for which the function f returns true will be returned. The obj can either be a structure or pointer to structure.
func SelectFieldsDeep ¶
func SelectFieldsDeep(obj interface{}, f func(string, reflect.StructField, reflect.Value) bool) (map[string]reflect.Value, error)
SelectFieldsDeep has the same functionality as FieldsDeep, but only the fields for which the function f returns true will be returned. The obj can either be a structure or pointer to structure.
func SelectStructFields ¶
func SelectStructFields(obj interface{}, f func(int, reflect.StructField) bool) ([]reflect.StructField, error)
SelectStructFields has the same functionality as StructFields, but only the fields for which the function f returns true will be returned. The obj can either be a structure or pointer to structure.
func SetEmbedField ¶
SetEmbedField sets a nested struct field using fieldPath. The rest of the functionality is the same as SetField. For example, fieldPath can be "FieldA.FieldB.FieldC", where FieldA and FieldB must be structures or pointers to structures. If FieldB does not exist, it will be automatically created. The obj can either be a structure or pointer to structure.
func SetField ¶
SetField sets the fieldName field of the obj object according to the fieldValue parameter. The obj can either be a structure or a pointer to a structure. The type of fieldValue must be compatible with the type of the fieldName field, otherwise it will panic.
func SetPrivateField ¶
SetPrivateField is similar to SetField, but it allows you to set private fields of an object. The obj can be either a structure or a pointer to a structure.
func StructField ¶
func StructField(obj interface{}, fieldName string) (reflect.StructField, error)
StructField returns the reflect.StructField of the provided obj field. The obj can either be a structure or pointer to structure.
func StructFieldKind ¶
StructFieldKind returns the reflect.Kind of the provided obj field. The obj can either be a structure or pointer to structure.
func StructFieldTag ¶
StructFieldTag returns the reflect.StructTag of the provided obj field. The obj parameter can either be a structure or pointer to structure.
func StructFieldTagValue ¶
StructFieldTagValue returns the provided obj field tag value. The obj parameter can either be a structure or pointer to structure.
func StructFieldType ¶
StructFieldType returns the reflect.Type of the provided obj field. The obj can either be a structure or pointer to structure.
func StructFieldTypeStr ¶
StructFieldTypeStr returns the string of reflect.Type of the provided obj field. The obj can either be a structure or pointer to structure.
func StructFields ¶
func StructFields(obj interface{}) ([]reflect.StructField, error)
StructFields returns a slice of reflect.StructField containing all the fields of the obj. The obj can either be a structure or a pointer to a structure.
func StructFieldsFlatten ¶
func StructFieldsFlatten(obj interface{}) ([]reflect.StructField, error)
StructFieldsFlatten returns "flattened" struct fields. Note that StructFieldsFlatten treats fields from anonymous inner structs as normal fields.
func Type ¶
Type returns the reflection type of obj. If obj is a pointer, it will be automatically dereferenced once.
func TypePenetrateElem ¶
TypePenetrateElem performs the same functionality as Type, but it will parse through all pointers until the final type is reached.
func Value ¶
Value returns the reflection value of obj. If obj is a pointer, it will be automatically dereferenced once.
func ValuePenetrateElem ¶
ValuePenetrateElem performs the same functionality as Value, but it will parse through all pointers until the final type is reached.
Types ¶
This section is empty.