Documentation ¶
Index ¶
- type Field
- type FieldTag
- type Struct
- func (s Struct) ByTagName(tag string) Struct
- func (s Struct) ByTagNameAll(tags ...string) Struct
- func (s Struct) ByTagNameAny(tags ...string) Struct
- func (s Struct) Field(name string) (Field, bool)
- func (s Struct) FilterFunc(fn func(Field) bool) Struct
- func (s Struct) OnlyTag(name string) []FieldTag
- func (s Struct) RemoveEmpty() Struct
- func (s Struct) RemoveFields(fields ...string) Struct
- func (s Struct) String() string
- type Tag
- type Tags
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Field ¶ added in v0.2.1
type Field struct { Name string `json:"name"` // Type is a type of a field, like "time.Time" or "*string" Type string `json:"type"` Tags Tags `json:"tags,omitempty"` }
Field represents one struct field.
type FieldTag ¶ added in v0.2.1
type FieldTag struct { Name string `json:"name"` // Type is a type of a field, like "time.Time" or "*string" Type string `json:"type"` Tag Tag `json:"tag,omitempty"` }
FieldTag is like Field but it has only one tag. It's used as an output of some functions (like Only()).
type Struct ¶ added in v0.2.1
type Struct []Field
Struct represents a single struct.
func Extract ¶
func Extract(src interface{}) Struct
Extract accept a struct (or a pointer to a struct) and returns a map of fields and their tags. If src is not a struct or a pointer to a struct, nil is returned.
func (Struct) ByTagName ¶ added in v0.2.1
ByTagName returns a slice of fields which contain given tag.
func (Struct) ByTagNameAll ¶ added in v1.1.0
ByTagNameAll returns a slice of fields which contain all of the tags.
func (Struct) ByTagNameAny ¶ added in v1.1.0
ByTagNameAny returns a slice of fields which contain at least one tag.
func (Struct) FilterFunc ¶ added in v0.2.1
FilterFunc returns a slice of fields, filtered by fn(field) == true.
func (Struct) OnlyTag ¶ added in v1.1.0
OnlyTag returns a slice of fields that match the given tag name. FieldTag is returned (instead of Struct like other filters) because the expected output is a slice of fields with only one tag.
func (Struct) RemoveEmpty ¶ added in v0.2.1
RemoveEmpty removes any field from a Struct that has an empty "Tags" field.
func (Struct) RemoveFields ¶ added in v0.2.1
RemoveFields removes fields by their names from a Struct and returns a new Struct.
type Tag ¶
type Tag struct { // Tag holds tag's name. Tag string `json:"tag"` Value string `json:"value"` // Optional holds the rest of the value which comes after the comma. // Example: In a tag like // `json:"id,pk,omitempty"` // Optional will contain // ["pk", "omitempty"] Optional []string `json:"optional,omitempty"` }
Tag represents a single struct tag, like
`json:"value"`.