Documentation ¶
Overview ¶
Package reflectme provides high level abstractions above the golang reflect library with some utilities functions.
The base code is a fork of https://github.com/oleiade/reflections. Then some other concepts and functions were added. Package reflections provides high level abstractions above the reflect library.
Index ¶
- Variables
- func Copy(from interface{}, to interface{}) error
- func CopyField(from interface{}, to interface{}, name string) error
- func CopyWithOptions(from interface{}, to interface{}, options CopyOptions) error
- func Fields(obj interface{}) ([]reflect.StructField, error)
- func FieldsNames(obj interface{}) ([]string, error)
- func GetField(obj interface{}, name string) (interface{}, error)
- func GetFieldKind(obj interface{}, name string) (reflect.Kind, error)
- func GetFieldTag(obj interface{}, fieldName, tagKey string) (string, error)
- func HasField(obj interface{}, name string) (bool, error)
- func IsStruct(obj interface{}) bool
- func IsZeroValue(i interface{}) bool
- func Items(obj interface{}) (map[string]interface{}, error)
- func SetField(s interface{}, name string, value interface{}) error
- func Tags(obj interface{}, key string) (map[string]string, error)
- type CopyOptions
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultCopyOptions are the default options for copy function DefaultCopyOptions = CopyOptions{ CopyZeroValues: true, IgnoreNotFoundFields: true, } )
Functions ¶
func Copy ¶
func Copy(from interface{}, to interface{}) error
Copy copies all values from "from" to "to" with DefaultCopyOptions
func CopyWithOptions ¶
func CopyWithOptions(from interface{}, to interface{}, options CopyOptions) error
CopyWithOptions copies all values from "from" to "to" with CopyOptions
func Fields ¶
func Fields(obj interface{}) ([]reflect.StructField, error)
Fields returns the struct fields list. obj can whether be a structure or pointer to structure.
func FieldsNames ¶
FieldsNames returns the struct fields names list. obj can whether be a structure or pointer to structure.
func GetField ¶
GetField returns the value of the provided obj field. obj can whether be a structure or pointer to structure.
func GetFieldKind ¶
GetFieldKind returns the kind of the provided obj field. obj can whether be a structure or pointer to structure.
func GetFieldTag ¶
GetFieldTag returns the provided obj field tag value. obj can whether be a structure or pointer to structure.
func HasField ¶
HasField checks if the provided field name is part of a struct. obj can whether be a structure or pointer to structure.
func IsStruct ¶
func IsStruct(obj interface{}) bool
IsStruct checks whether the kind of a type is a struct
func IsZeroValue ¶
func IsZeroValue(i interface{}) bool
IsZeroValue indicates if the interface has value according to golang spec: https://golang.org/ref/spec#The_zero_value
func Items ¶
Items returns the field - value struct pairs as a map. obj can whether be a structure or pointer to structure.
Types ¶
type CopyOptions ¶
CopyOptions are options for copy function