Documentation
¶
Overview ¶
Package structs provide several high level functions to manipulate struct, tag, and field.
Index ¶
- func ToMap(v any) (map[string]any, error)
- type Field
- func (f *Field) IsEmbedded() bool
- func (f *Field) IsExported() bool
- func (f *Field) IsNil() bool
- func (f *Field) IsSlice() bool
- func (f *Field) IsTargetType(targetType reflect.Kind) bool
- func (f *Field) IsZero() bool
- func (f *Field) Kind() reflect.Kind
- func (f *Field) Name() string
- func (f *Field) Tag() *Tag
- func (f *Field) Value() any
- type Struct
- type Tag
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. Play: https://go.dev/play/p/wV2PrbYm3Ec
func (*Field) IsExported ¶
IsExported returns true if the given field is exported. Play: https://go.dev/play/p/csK4AXYaNbJ
func (*Field) IsSlice ¶
IsSlice check if a struct field type is slice or not Play: https://go.dev/play/p/MKz4CgBIUrU
func (*Field) IsTargetType ¶ added in v2.2.9
IsTargetType check if a struct field type is target type or not Play: https://go.dev/play/p/Ig75P-agN39
func (*Field) IsZero ¶
IsZero returns true if the given field is zero value. Play: https://go.dev/play/p/RzqpGISf87r
func (*Field) Kind ¶
Kind returns the field's kind Play: https://go.dev/play/p/wg4NlcUNG5o
func (*Field) Name ¶
Name returns the name of the given field Play: https://go.dev/play/p/zfIGlqsatee
func (*Field) Tag ¶
Tag returns the value that the key in the tag string. Play: https://go.dev/play/p/DVrx5HvvUJr
func (*Field) Value ¶
Value returns the underlying value of the field. Play: https://go.dev/play/p/qufYEU2o4Oi
type Struct ¶
type Struct struct {
TagName string
// contains filtered or unexported fields
}
Struct is abstract struct for provide several high level functions
func New ¶
New returns a new *Struct Play: https://go.dev/play/p/O29l8kk-Z17
func (*Struct) Field ¶
Field returns a Field if the given field name was found Play: https://go.dev/play/p/KocZMSYarza
func (*Struct) Fields ¶
Fields returns all the struct fields within a slice Play: https://go.dev/play/p/w3Kk_CyVY7D
func (*Struct) IsStruct ¶
IsStruct returns true if the given rvalue is a struct Play: https://go.dev/play/p/bU2FSdkbK1C
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. Play: https://go.dev/play/p/qQbLySBgerZ
func (*Struct) TypeName ¶ added in v2.3.8
TypeName return struct type name Play: https://go.dev/play/p/todo