Documentation
¶
Overview ¶
Package structs provides functions for struct conversion.
Inspired and improved from: https://github.com/fatih/structs
Index ¶
- func FieldMap(pointer interface{}, priority []string) (map[string]*Field, error)
- func ParseTag(tag string) map[string]string
- func TagMapField(object interface{}, priority []string) (map[string]*Field, error)
- func TagMapName(pointer interface{}, priority []string) (map[string]string, error)
- type Field
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FieldMap ¶ added in v1.15.4
FieldMap retrieves and returns struct field as map[name/tag]*Field from `pointer`.
The parameter `pointer` should be type of struct/*struct.
The parameter `priority` specifies the priority tag array for retrieving from high to low. If it's given `nil`, it returns map[name]*Field, of which the `name` is attribute name.
Note that it only retrieves the exported attributes with first letter up-case from struct.
func TagMapField ¶
TagMapField retrieves struct tags as map[tag]*Field from `pointer`, and returns it. The parameter `object` should be either type of struct/*struct/[]struct/[]*struct.
Note that it only retrieves the exported attributes with first letter up-case from struct.
func TagMapName ¶
TagMapName retrieves and returns struct tags as map[tag]attribute from `pointer`.
The parameter `pointer` should be type of struct/*struct.
Note that it only retrieves the exported attributes with first letter up-case from struct.
Types ¶
type Field ¶
type Field struct { Value reflect.Value // The underlying value of the field. Field reflect.StructField // The underlying field of the field. TagValue string // Retrieved tag value. There might be more than one tags in the field, but only one can be retrieved according to calling function rules. }
Field contains information of a struct field .
func TagFields ¶ added in v1.10.1
TagFields retrieves and returns struct tags as []*Field from `pointer`.
The parameter `pointer` should be type of struct/*struct.
Note that it only retrieves the exported attributes with first letter up-case from struct.
func (*Field) IsEmbedded ¶ added in v1.14.3
IsEmbedded returns true if the given field is an anonymous field (embedded)
func (*Field) IsExported ¶ added in v1.14.3
IsExported returns true if the given field is exported.
func (*Field) OriginalKind ¶ added in v1.15.5
OriginalKind retrieves and returns the original reflect.Kind for Value of Field `f`.
type Type ¶ added in v1.15.4
Type wraps reflect.Type for additional features.
func StructType ¶ added in v1.15.4
StructType retrieves and returns the struct Type of specified struct/*struct. The parameter `object` should be either type of struct/*struct/[]struct/[]*struct.