Documentation ¶
Index ¶
- Variables
- func Fields(obj interface{}) ([]string, error)
- func FieldsDeep(obj interface{}) ([]string, error)
- func GetField(obj interface{}, name string) (interface{}, error)
- func GetFieldKind(obj interface{}, name string) (reflect.Kind, error)
- func GetFieldNameByTagValue(obj interface{}, tagKey, tagValue string) (string, error)
- func GetFieldTag(obj interface{}, fieldName, tagKey string) (string, error)
- func GetFieldType(obj interface{}, name string) (string, error)
- func HasField(obj interface{}, name string) (bool, error)
- func Items(obj interface{}) (map[string]interface{}, error)
- func ItemsDeep(obj interface{}) (map[string]interface{}, error)
- func SetField(obj interface{}, name string, value interface{}) error
- func Tags(obj interface{}, key string) (map[string]string, error)
- func TagsDeep(obj interface{}, key string) (map[string]string, error)
Constants ¶
This section is empty.
Variables ¶
var ErrUnexportedField = errors.New("unexported field")
ErrUnexportedField indicates that an operation failed as a result of applying to a non-exported struct field.
var ErrUnsupportedType = errors.New("unsupported type")
ErrUnsupportedType indicates that the provided type doesn't support the requested reflection operation.
Functions ¶
func Fields ¶
Fields returns the struct fields names list. The `obj` parameter can either be a structure or pointer to structure.
func FieldsDeep ¶
FieldsDeep returns "flattened" fields.
Note that FieldsDeept treats fields from anonymous inner structs as normal fields.
func GetField ¶
GetField returns the value of the provided obj field. The `obj` can either be a structure or pointer to structure.
func GetFieldKind ¶
GetFieldKind returns the kind of the provided obj field. The `obj` can either be a structure or pointer to structure.
func GetFieldNameByTagValue ¶
GetFieldNameByTagValue looks up a field with a matching `{tagKey}:"{tagValue}"` tag in the provided `obj` item. The `obj` parameter must be a `struct`, or a `pointer` to one. If the `obj` parameter doesn't have a field tagged with the `tagKey`, and the matching `tagValue`, this function returns an error.
func GetFieldTag ¶
GetFieldTag returns the provided obj field tag value. The `obj` parameter can either be a structure or pointer to structure.
func GetFieldType ¶
GetFieldType returns the kind of the provided obj field. The `obj` can either be a structure or pointer to structure.
func HasField ¶
HasField checks if the provided `obj` struct has field named `name`. The `obj` can either be a structure or pointer to structure.
func Items ¶
Items returns the field:value struct pairs as a map. The `obj` parameter can either be a structure or pointer to structure.
func ItemsDeep ¶
ItemsDeep returns "flattened" items. Note that ItemsDeep will treat fields from anonymous inner structs as normal fields.
func SetField ¶
SetField sets the provided obj field with provided value.
The `obj` parameter must be a pointer to a struct, otherwise it soundly fails. The provided `value` type should match with the struct field being set.
Types ¶
This section is empty.