Documentation ¶
Overview ¶
Package reflector provides utilities for reflection
Index ¶
- Variables
- func CallFunc(object interface{}, args ...interface{}) (interface{}, error)
- func CallMethodByName(object interface{}, name string, args ...interface{}) (interface{}, error)
- func DeepFields(reflectType reflect.Type) []reflect.StructField
- func FindEmbeddedFieldTag(object interface{}, fieldName, tagName string) (t string, ok bool)
- func FindFieldByTag(obj interface{}, key, name string) (field reflect.StructField, ok bool)
- func GetEmbeddedField(object interface{}, nameOrType interface{}, dataTypes ...reflect.Kind) (field reflect.StructField)
- func GetEmbeddedFieldByType(typ reflect.Type, nameOrType interface{}, kind ...reflect.Kind) (field reflect.StructField, ok bool)
- func GetEmbeddedFieldType(object interface{}, expected interface{}) (field reflect.StructField, ok bool)
- func GetEmbeddedFields(object interface{}, kind ...reflect.Kind) (fields []reflect.StructField)
- func GetEmbeddedFieldsByType(typ reflect.Type, kind ...reflect.Kind) (fields []reflect.StructField)
- func GetFieldValue(f interface{}, name string) reflect.Value
- func GetFullName(object interface{}) (name string)
- func GetFuncName(fn interface{}) (name string)
- func GetKind(kind reflect.Kind) reflect.Kind
- func GetKindByType(typ reflect.Type) reflect.Kind
- func GetKindByValue(val reflect.Value) reflect.Kind
- func GetLowerCamelFullName(object interface{}) (name string)
- func GetLowerCamelFullNameByType(objType reflect.Type) (name string)
- func GetLowerCamelName(object interface{}) (name string)
- func GetName(data interface{}) (name string)
- func GetObjectType(object interface{}) (typ reflect.Type, ok bool)
- func GetPkgAndName(object interface{}) (pkgName, name string)
- func GetPkgPath(object interface{}) string
- func GetType(data interface{}) (typ reflect.Type, err error)
- func HasEmbeddedField(object interface{}, name string) bool
- func HasEmbeddedFieldType(object interface{}, expected interface{}) (found bool)
- func HasField(object interface{}, name string) bool
- func Implements(object interface{}, interfaceType interface{}) (ok bool)
- func Indirect(reflectValue reflect.Value) reflect.Value
- func IndirectType(reflectType reflect.Type) reflect.Type
- func IndirectValue(object interface{}) (reflectValue reflect.Value)
- func IsValidObjectType(inst interface{}) bool
- func NewReflectType(st interface{}) interface{}
- func ParseObjectName(obj interface{}, eliminator string) string
- func ParseObjectPkgName(obj interface{}) string
- func SetFieldValue(object interface{}, name string, value interface{}) error
- func Validate(toValue interface{}) (*reflect.Value, error)
- func ValidateReflectType(obj interface{}, ...) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidInput means that the input is invalid ErrInvalidInput = errors.New("input is invalid") // ErrInvalidMethod means that the method is invalid ErrInvalidMethod = errors.New("method is invalid") // ErrInvalidFunc means that the func is invalid ErrInvalidFunc = errors.New("func is invalid") // ErrFieldCanNotBeSet means that the field can not be set ErrFieldCanNotBeSet = errors.New("field can not be set") )
Functions ¶
func CallFunc ¶ added in v0.4.0
func CallFunc(object interface{}, args ...interface{}) (interface{}, error)
CallFunc call function
func CallMethodByName ¶
CallMethodByName call method
func DeepFields ¶
func DeepFields(reflectType reflect.Type) []reflect.StructField
DeepFields iterate struct field
func FindEmbeddedFieldTag ¶ added in v0.8.0
FindEmbeddedFieldTag find embedded field tag
func FindFieldByTag ¶ added in v1.3.0
func FindFieldByTag(obj interface{}, key, name string) (field reflect.StructField, ok bool)
FindFieldByTag find field by tag
func GetEmbeddedField ¶ added in v0.9.3
func GetEmbeddedField(object interface{}, nameOrType interface{}, dataTypes ...reflect.Kind) (field reflect.StructField)
GetEmbeddedField get embedded interface field
func GetEmbeddedFieldByType ¶ added in v0.9.3
func GetEmbeddedFieldByType(typ reflect.Type, nameOrType interface{}, kind ...reflect.Kind) (field reflect.StructField, ok bool)
GetEmbeddedFieldByType get embedded interface field by type
func GetEmbeddedFieldType ¶ added in v1.2.0
func GetEmbeddedFieldType(object interface{}, expected interface{}) (field reflect.StructField, ok bool)
GetEmbeddedFieldType check if has embedded fieled
func GetEmbeddedFields ¶ added in v0.11.0
func GetEmbeddedFields(object interface{}, kind ...reflect.Kind) (fields []reflect.StructField)
GetEmbeddedFields get embedded interface fields
func GetEmbeddedFieldsByType ¶ added in v0.11.0
GetEmbeddedFieldsByType get embedded interface fields by type
func GetFieldValue ¶
GetFieldValue get field value
func GetFullName ¶ added in v0.9.0
func GetFullName(object interface{}) (name string)
GetFullName get the object name with package name, e.g. pkg.Object
func GetFuncName ¶ added in v0.9.4
func GetFuncName(fn interface{}) (name string)
GetFuncName get func name
func GetKindByType ¶ added in v0.5.0
GetKindByType get kind by type
func GetKindByValue ¶ added in v0.5.0
GetKindByValue get kind by value
func GetLowerCamelFullName ¶ added in v0.9.3
func GetLowerCamelFullName(object interface{}) (name string)
GetLowerCamelFullName get the object name with package name, e.g. pkg.objectName
func GetLowerCamelFullNameByType ¶ added in v0.9.3
GetLowerCamelFullNameByType get the object name with package name by type, e.g. pkg.Object
func GetLowerCamelName ¶ added in v0.9.3
func GetLowerCamelName(object interface{}) (name string)
GetLowerCamelName get lower case object name
func GetObjectType ¶ added in v0.9.7
GetObjectType get the function output data type
func GetPkgAndName ¶ added in v0.9.0
func GetPkgAndName(object interface{}) (pkgName, name string)
GetPkgAndName get the package name and the object name with, e.g. pkg, Object
func GetPkgPath ¶ added in v0.3.0
func GetPkgPath(object interface{}) string
GetPkgPath get the package patch
func GetType ¶ added in v0.5.0
GetType get object data type
func HasEmbeddedField ¶
HasEmbeddedField check if has embedded fieled
func HasEmbeddedFieldType ¶ added in v0.9.7
func HasEmbeddedFieldType(object interface{}, expected interface{}) (found bool)
HasEmbeddedFieldType check if has embedded fieled
func HasField ¶
HasField check if has specific field
func Implements ¶ added in v1.3.0
func Implements(object interface{}, interfaceType interface{}) (ok bool)
Implements
func IndirectType ¶
IndirectType get indirect type
func IndirectValue ¶ added in v1.3.0
IndirectValue get indirect value
func IsValidObjectType ¶ added in v0.9.5
func IsValidObjectType(inst interface{}) bool
IsValidObjectType check if is valid object type
func NewReflectType ¶
func NewReflectType(st interface{}) interface{}
NewReflectType create instance by tyep
func ParseObjectName ¶ added in v0.3.0
ParseObjectName e.g. ExampleObject => example
func ParseObjectPkgName ¶ added in v0.4.0
func ParseObjectPkgName(obj interface{}) string
ParseObjectPkgName e.g. ExampleObject => example
func SetFieldValue ¶
SetFieldValue set field value
Types ¶
This section is empty.