Documentation ¶
Overview ¶
Package structs provide several high level functions to manipulate struct, tag, and field.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Field ¶
type Field struct { Struct // contains filtered or unexported fields }
Field is abstract struct field for provide several high level functions
func (*Field) IsEmbedded ¶
IsEmbedded returns true if the given field is an embedded field.
func (*Field) IsExported ¶
IsExported returns true if the given field is exported.
type Struct ¶
type Struct struct { TagName string // contains filtered or unexported fields }
Struct is abstract struct for provide several high level functions
func (*Struct) ToMap ¶
ToMap converts the given struct to a map[string]any, where the keys of the keys are the field names and the values of the map are the values of the fields. The default map key is the struct field name, but you can change it. The `json` key is the default tag key. Example:
// default Name string `json:"name"` // ignore the field Name string // no tag Age string `json:"-"` // json ignore tag sex string // unexported field Goal int `json:"goal,omitempty"` // omitempty if the field is zero value // custom map key Name string `json:"myName"`
ToMap convert the exported fields of a struct to map.