hiboot: hidevops.io/hiboot/pkg/utils/reflector Index | Files | Directories

package reflector

import "hidevops.io/hiboot/pkg/utils/reflector"

Package reflector provides utilities for reflection


Package Files



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")

func CallFunc Uses

func CallFunc(object interface{}, args ...interface{}) (interface{}, error)

CallFunc call function

func CallMethodByName Uses

func CallMethodByName(object interface{}, name string, args ...interface{}) (interface{}, error)

CallMethodByName call method

func DeepFields Uses

func DeepFields(reflectType reflect.Type) []reflect.StructField

DeepFields iterate struct field

func FindEmbeddedFieldTag Uses

func FindEmbeddedFieldTag(object interface{}, fieldName, tagName string) (t string, ok bool)

FindEmbeddedFieldTag find embedded field tag

func FindFieldByTag Uses

func FindFieldByTag(obj interface{}, key, name string) (field reflect.StructField, ok bool)

FindFieldByTag find field by tag

func GetEmbeddedField Uses

func GetEmbeddedField(object interface{}, nameOrType interface{}, dataTypes ...reflect.Kind) (field reflect.StructField)

GetEmbeddedField get embedded interface field

func GetEmbeddedFieldByType Uses

func GetEmbeddedFieldByType(typ reflect.Type, nameOrType interface{}, kind ...reflect.Kind) (field reflect.StructField, ok bool)

GetEmbeddedFieldByType get embedded interface field by type

func GetEmbeddedFieldType Uses

func GetEmbeddedFieldType(object interface{}, expected interface{}) (field reflect.StructField, ok bool)

GetEmbeddedFieldType check if has embedded fieled

func GetEmbeddedFields Uses

func GetEmbeddedFields(object interface{}, kind ...reflect.Kind) (fields []reflect.StructField)

GetEmbeddedFields get embedded interface fields

func GetEmbeddedFieldsByType Uses

func GetEmbeddedFieldsByType(typ reflect.Type, kind ...reflect.Kind) (fields []reflect.StructField)

GetEmbeddedFieldsByType get embedded interface fields by type

func GetFieldValue Uses

func GetFieldValue(f interface{}, name string) reflect.Value

GetFieldValue get field value

func GetFullName Uses

func GetFullName(object interface{}) (name string)

GetFullName get the object name with package name, e.g. pkg.Object

func GetFuncName Uses

func GetFuncName(fn interface{}) (name string)

GetFuncName get func name

func GetKind Uses

func GetKind(kind reflect.Kind) reflect.Kind

GetKind get kind

func GetKindByType Uses

func GetKindByType(typ reflect.Type) reflect.Kind

GetKindByType get kind by type

func GetKindByValue Uses

func GetKindByValue(val reflect.Value) reflect.Kind

GetKindByValue get kind by value

func GetLowerCamelFullName Uses

func GetLowerCamelFullName(object interface{}) (name string)

GetLowerCamelFullName get the object name with package name, e.g. pkg.objectName

func GetLowerCamelFullNameByType Uses

func GetLowerCamelFullNameByType(objType reflect.Type) (name string)

GetLowerCamelFullNameByType get the object name with package name by type, e.g. pkg.Object

func GetLowerCamelName Uses

func GetLowerCamelName(object interface{}) (name string)

GetLowerCamelName get lower case object name

func GetName Uses

func GetName(data interface{}) (name string)

GetName get object name

func GetObjectType Uses

func GetObjectType(object interface{}) (typ reflect.Type, ok bool)

GetObjectType get the function output data type

func GetPkgAndName Uses

func GetPkgAndName(object interface{}) (pkgName, name string)

GetPkgAndName get the package name and the object name with, e.g. pkg, Object

func GetPkgPath Uses

func GetPkgPath(object interface{}) string

GetPkgPath get the package patch

func GetType Uses

func GetType(data interface{}) (typ reflect.Type, err error)

GetType get object data type

func HasEmbeddedField Uses

func HasEmbeddedField(object interface{}, name string) bool

HasEmbeddedField check if has embedded fieled

func HasEmbeddedFieldType Uses

func HasEmbeddedFieldType(object interface{}, expected interface{}) (found bool)

HasEmbeddedFieldType check if has embedded fieled

func HasField Uses

func HasField(object interface{}, name string) bool

HasField check if has specific field

func Implements Uses

func Implements(object interface{}, interfaceType interface{}) (ok bool)


func Indirect Uses

func Indirect(reflectValue reflect.Value) reflect.Value

Indirect get indirect value

func IndirectType Uses

func IndirectType(reflectType reflect.Type) reflect.Type

IndirectType get indirect type

func IndirectValue Uses

func IndirectValue(object interface{}) (reflectValue reflect.Value)

IndirectValue get indirect value

func IsValidObjectType Uses

func IsValidObjectType(inst interface{}) bool

IsValidObjectType check if is valid object type

func NewReflectType Uses

func NewReflectType(st interface{}) interface{}

NewReflectType create instance by tyep

func ParseObjectName Uses

func ParseObjectName(obj interface{}, eliminator string) string

ParseObjectName e.g. ExampleObject => example

func ParseObjectPkgName Uses

func ParseObjectPkgName(obj interface{}) string

ParseObjectPkgName e.g. ExampleObject => example

func SetFieldValue Uses

func SetFieldValue(object interface{}, name string, value interface{}) error

SetFieldValue set field value

func Validate Uses

func Validate(toValue interface{}) (*reflect.Value, error)

Validate validate value

func ValidateReflectType Uses

func ValidateReflectType(obj interface{}, callback func(value *reflect.Value, reflectType reflect.Type, fieldSize int, isSlice bool) error) error

ValidateReflectType validate reflect type and iterate all fields



Package reflector imports 6 packages (graph) and is imported by 26 packages. Updated 2019-10-16. Refresh now. Tools for package owners.