Documentation ¶
Overview ¶
Package structs contains various utilities functions to work with structs.
Index ¶
- Variables
- func FillMap(s interface{}, out map[string]interface{})
- func GoMap(s interface{}) map[string]interface{}
- func HasZero(s interface{}) bool
- func IsStruct(s interface{}) bool
- func IsZero(s interface{}) bool
- func Merge(sources ...map[string]any) map[string]any
- func Name(s interface{}) string
- func Names(s interface{}) []string
- func ParseInt(v interface{}) (int64, bool)
- func ParseInt64(v interface{}) (int64, bool)
- func ParseNumber(v interface{}) (float64, bool)
- func ParseString(v interface{}) (string, bool)
- func Values(s interface{}) []interface{}
- type Field
- func (f *Field) Field(name string) *Field
- func (f *Field) FieldOk(name string) (*Field, bool)
- func (f *Field) Fields() []*Field
- func (f *Field) IsEmbedded() bool
- func (f *Field) IsExported() bool
- func (f *Field) IsZero() bool
- func (f *Field) Kind() reflect.Kind
- func (f *Field) Name() string
- func (f *Field) Set(val interface{}) error
- func (f *Field) Tag(key string) string
- func (f *Field) Value() interface{}
- func (f *Field) Zero() error
- type JSONer
- type Map
- func (m *Map) Append(source *Map) *Map
- func (m *Map) Check(s ...string) int
- func (m *Map) Clone() Map
- func (m *Map) Delete(key string) bool
- func (m *Map) DeletePath(keys []string) bool
- func (m *Map) Expect(keys []string) Map
- func (m Map) Get(key string) any
- func (m *Map) GetArray(s string) []any
- func (m *Map) GetArrayD(s string, d []any) []any
- func (m *Map) GetBool(s string) bool
- func (m *Map) GetBoolD(s string, b bool) bool
- func (m *Map) GetBytes(s string) []byte
- func (m *Map) GetBytesD(s string, d []byte) []byte
- func (m *Map) GetD(s string, d any) any
- func (m *Map) GetInt64(s string) (int64, bool)
- func (m *Map) GetInt64D(s string, d int64) int64
- func (m *Map) GetMap(s string) *Map
- func (m *Map) GetMapArray(s string) []*Map
- func (m *Map) GetMapArrayD(s string, d []*Map) []*Map
- func (m *Map) GetMapD(s string, d *Map) *Map
- func (m *Map) GetNumber(s string) (float64, bool)
- func (m *Map) GetNumberD(s string, d float64) float64
- func (m *Map) GetPath(keys []string) any
- func (m *Map) GetString(s string) string
- func (m *Map) GetStringArray(s string) []string
- func (m *Map) GetStringArrayD(s string, d []string) []string
- func (m *Map) GetStringD(s string, d string) string
- func (m *Map) GoMap() map[string]any
- func (m *Map) Has(key string) bool
- func (m *Map) HasPath(keys []string) bool
- func (m *Map) Join(source *Map) *Map
- func (m *Map) Map() *Map
- func (m Map) MarshalJSON() ([]byte, error)
- func (m *Map) Merge(maps ...*Map) *Map
- func (m *Map) Only(keys []string) *Map
- func (m *Map) ParseJSON(b []byte) error
- func (m *Map) Query(key string) (any, error)
- func (m *Map) Range(f func(key string, value any) bool)
- func (m *Map) Replace(s string, v any) *Map
- func (m *Map) ReplaceFromMap(key string, v *Map) *Map
- func (m *Map) ReplaceJoin(source *Map) *Map
- func (m *Map) Set(key string, v any) *Map
- func (m *Map) SetNil(key string, val any) *Map
- func (m *Map) SetPath(keys []string, v any) *Map
- func (m *Map) SortKeys() []string
- func (m Map) String() string
- func (m *Map) ToEncodeURL() string
- func (m *Map) ToJSON() (v []byte, err error)
- func (m Map) UnmarshalJSON(bytes []byte) error
- type Setting
- type SettingOption
- type String
- type Stringer
- type Struct
- type XMLer
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultTagName is the default tag name for struct fields which provides // a more granular to tweak certain structs. Lookup the necessary functions // for more info. DefaultTagName = "structs" // struct's field default tag name )
var ErrNilMap = errors.New("nil map")
ErrNilMap ...
var ErrUnsupportedType = errors.New("error unsupported type")
Functions ¶
func FillMap ¶
func FillMap(s interface{}, out map[string]interface{})
FillMap is the same as Map. Instead of returning the output, it fills the given map.
func GoMap ¶
func GoMap(s interface{}) map[string]interface{}
GoMap converts the given struct to a map[string]interface{}. For more info refer to structData types Map() method. It panics if s's kind is not struct.
func HasZero ¶
func HasZero(s interface{}) bool
HasZero returns true if any field is equal to a zero value. For more info refer to structData types HasZero() method. It panics if s's kind is not struct.
func IsStruct ¶
func IsStruct(s interface{}) bool
IsStruct returns true if the given variable is a struct or a pointer to struct.
func IsZero ¶
func IsZero(s interface{}) bool
IsZero returns true if all fields is equal to a zero value. For more info refer to structData types IsZero() method. It panics if s's kind is not struct.
func Name ¶
func Name(s interface{}) string
Name returns the structs's type name within its package. It returns an empty string for unnamed types. It panics if s's kind is not struct.
func Names ¶
func Names(s interface{}) []string
Names returns a slice of field names. For more info refer to structData types Names() method. It panics if s's kind is not struct.
func ParseInt64 ¶
func ParseNumber ¶
ParseNumber parse interface to number
func ParseString ¶
ParseString parse interface to string
Types ¶
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field represents a single struct field that encapsulates high level functions around the field.
func Fields ¶
func Fields(s interface{}) []*Field
Fields returns a slice of *Field. For more info refer to structData types Fields() method. It panics if s's kind is not struct.
func (*Field) Field ¶
Field returns the field from a nested struct. It panics if the nested struct is not exported or if the field was not found.
func (*Field) FieldOk ¶
FieldOk returns the field from a nested struct. The boolean returns whether the field was found (true) or not (false).
func (*Field) Fields ¶
Fields returns a slice of Fields. This is particular handy to get the fields of a nested struct . A struct tag with the content of "-" ignores the checking of that particular field. Example:
// Field is ignored by this package. Field *http.Request `structs:"-"`
It panics if field is not exported or if field's kind is not struct
func (*Field) IsEmbedded ¶
IsEmbedded returns true if the given field is an anonymous field (embedded)
func (*Field) IsExported ¶
IsExported returns true if the given field is exported.
func (*Field) IsZero ¶
IsZero returns true if the given field is not initialized (has a zero value). It panics if the field is not exported.
func (*Field) Set ¶
Set sets the field to given value v. It returns an error if the field is not settable (not addressable or not exported) or if the given value's type doesn't match the fields type.
func (*Field) Tag ¶
Tag returns the value associated with key in the tag string. If there is no such key in the tag, Tag returns the empty string.
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
func (*Map) Append ¶
Append append source map to target map; if the key value is exist and it is a []interface value, this will append into it otherwise, it will replace the value
func (*Map) Check ¶
Check check all input keys return -1 if all is exist return index when not found
func (*Map) DeletePath ¶
DeletePath delete keys value if keys is exist
func (*Map) GetMapArray ¶
GetMapArray get map from map with out default
func (*Map) GetMapArrayD ¶
GetMapArrayD get map from map with default
func (*Map) GetNumberD ¶
GetNumberD get float64 from map with default
func (*Map) GetPath ¶
GetPath returns the element in the tree indicated by 'keys'. If keys is of length zero, the current tree is returned.
func (*Map) GetStringArray ¶
GetStringArray get string from map with out default
func (*Map) GetStringArrayD ¶
GetStringD get string from map with default
func (*Map) GetStringD ¶
GetStringD get string from map with default
func (Map) MarshalJSON ¶
func (*Map) Merge ¶
Merge marge all maps to target Map, the newer value will replace the older value
func (*Map) ReplaceFromMap ¶
ReplaceFromMap replace will set value from other map, if the key is exist from the both map
func (*Map) ReplaceJoin ¶
ReplaceJoin insert map s to m with replace
func (*Map) SetPath ¶
SetPath is the same as SetPath, but allows you to provide comment information to the key, that will be reused by Marshal().
func (Map) UnmarshalJSON ¶
type SettingOption ¶
type SettingOption func(op *Setting)