Documentation
¶
Index ¶
- Constants
- func DeepGet(mp map[string]any, path string) (val interface{})
- func FlatWithFunc(mp map[string]any, fn reflects.FlatFunc)
- func Flatten(mp map[string]any) map[string]interface{}
- func FormatIndent(mp any, indent string) string
- func GetByPath(path string, mp map[string]any) (val interface{}, ok bool)
- func HasAllKeys(mp any, keys ...any) (ok bool, noKey interface{})
- func HasKey(mp, key any) (ok bool)
- func HttpQueryString(data map[string]any) string
- func KeyToLower(src map[string]string) map[string]string
- func Keys(mp any) (keys []string)
- func MakeByKeys(keys []string, val any) (mp map[string]interface{})
- func MakeByPath(path string, val interface{}) (mp map[string]interface{})
- func MergeSMap(src, dst map[string]string, ignoreCase bool) map[string]string
- func MergeStringMap(src, dst map[string]string, ignoreCase bool) map[string]string
- func QuietGet(mp map[string]any, path string) (val interface{})
- func SetByKeys(mp *map[string]any, keys []string, val any) (err error)
- func SetByPath(mp *map[string]any, path string, val any) error
- func ToString(mp map[string]any) string
- func ToString2(mp any) string
- func ToStringMap(src map[string]any) map[string]string
- func Values(mp any) (values []interface{})
- type Aliases
- type Data
- func (d Data) Bool(key string) bool
- func (d Data) Default(key string, def any) interface{}
- func (d Data) Get(key string) interface{}
- func (d Data) GetByPath(path string) (interface{}, bool)
- func (d Data) Has(key string) bool
- func (d Data) Int(key string) int
- func (d Data) Int64(key string) int64
- func (d Data) IsEmtpy() bool
- func (d Data) Keys() []string
- func (d Data) Set(key string, val any)
- func (d Data) SetByKeys(keys []string, value any) error
- func (d Data) SetByPath(path string, value any) error
- func (d Data) Str(key string) string
- func (d Data) StrSplit(key, sep string) []string
- func (d Data) String() string
- func (d Data) StringMap(key string) map[string]string
- func (d Data) Strings(key string) []string
- func (d Data) StringsByStr(key string) []string
- func (d Data) Sub(key string) Data
- func (d Data) ToStringMap() map[string]string
- func (d Data) Value(key string) (interface{}, bool)
- type Map
- type MapFormatter
- type SMap
- func (m SMap) Bool(key string) bool
- func (m SMap) Default(key, defVal string) string
- func (m SMap) Get(key string) string
- func (m SMap) Has(key string) bool
- func (m SMap) HasValue(val string) bool
- func (m SMap) Int(key string) int
- func (m SMap) Int64(key string) int64
- func (m SMap) Ints(key string) []int
- func (m SMap) IsEmpty() bool
- func (m SMap) Keys() []string
- func (m SMap) Str(key string) string
- func (m SMap) String() string
- func (m SMap) Strings(key string) (ss []string)
- func (m SMap) Value(key string) (string, bool)
- func (m SMap) Values() []string
Constants ¶
const ( ValSepStr = "," ValSepChar = ',' KeySepStr = "." KeySepChar = '.' )
Key, value sep char consts
Variables ¶
This section is empty.
Functions ¶
func FlatWithFunc ¶ added in v0.5.12
FlatWithFunc flat a tree-map with custom collect handle func
func Flatten ¶ added in v0.5.12
Flatten convert tree map to flat key-value map.
Examples:
{"top": {"sub": "value", "sub2": "value2"} } -> {"top.sub": "value", "top.sub2": "value2" }
func FormatIndent ¶ added in v0.5.3
FormatIndent format map data to string with newline and indent.
func HasAllKeys ¶ added in v0.5.8
func HasAllKeys(mp any, keys ...any) (ok bool, noKey interface{})
HasAllKeys check of the given map.
func HttpQueryString ¶ added in v0.3.9
HttpQueryString convert map[string]any data to http query string.
func KeyToLower ¶
KeyToLower convert keys to lower case.
func MakeByKeys ¶ added in v0.5.8
MakeByKeys build new value by key names
Example:
// case 1: []string{"site", "info"} -> map[string]interface{} { site: {info: val} } // case 2, last key is slice: []string{"site", "tags[1]"} -> map[string]interface{} { site: {tags: [val]} }
func MakeByPath ¶ added in v0.5.8
MakeByPath build new value by key names
Example:
"site.info" -> map[string]interface{} { site: {info: val} } // case 2, last key is slice: "site.tags[1]" -> map[string]interface{} { site: {tags: [val]} }
func MergeStringMap ¶
MergeStringMap simple merge two string map. merge src to dst map
func SetByKeys ¶ added in v0.5.8
SetByKeys set sub-map value by path keys. Supports dot syntax to set deep values.
For example:
SetByKeys([]string{"name", "first"}, "Mat")
func SetByPath ¶ added in v0.5.8
SetByPath set sub-map value by key path. Supports dot syntax to set deep values.
For example:
SetByPath("name.first", "Mat")
func ToString2 ¶ added in v0.5.3
func ToString2(mp any) string
ToString2 simple and quickly convert a map to string.
func ToStringMap ¶ added in v0.3.9
ToStringMap convert map[string]any to map[string]string
Types ¶
type Aliases ¶ added in v0.3.9
Aliases implemented a simple string alias map.
func (Aliases) AddAliasMap ¶ added in v0.3.9
AddAliasMap to the Aliases
func (Aliases) AddAliases ¶ added in v0.3.9
AddAliases to the Aliases
func (Aliases) ResolveAlias ¶ added in v0.3.9
ResolveAlias by given name.
type Data ¶ added in v0.3.9
type Data map[string]any
Data an map data type
func (Data) Get ¶ added in v0.3.9
Get value from the data map. Supports dot syntax to get deep values. eg: top.sub
func (Data) GetByPath ¶ added in v0.5.3
GetByPath get value from the data map by path. eg: top.sub Supports dot syntax to get deep values.
func (Data) SetByKeys ¶ added in v0.5.9
SetByKeys sets a value in the map by path keys. Supports dot syntax to set deep values.
For example:
d.SetByKeys([]string{"name", "first"}, "Mat")
func (Data) SetByPath ¶ added in v0.5.8
SetByPath sets a value in the map. Supports dot syntax to set deep values.
For example:
d.SetByPath("name.first", "Mat")
func (Data) StringsByStr ¶ added in v0.5.3
StringsByStr value get by key
func (Data) ToStringMap ¶ added in v0.5.3
ToStringMap convert to map[string]string
type MapFormatter ¶ added in v0.5.3
type MapFormatter struct { comdef.BaseFormatter // Prefix string for each element Prefix string // Indent string for each element Indent string // ClosePrefix string for last "}" ClosePrefix string }
MapFormatter struct
func (*MapFormatter) Format ¶ added in v0.5.3
func (f *MapFormatter) Format() string
Format to string
func (*MapFormatter) FormatTo ¶ added in v0.5.3
func (f *MapFormatter) FormatTo(w io.Writer)
FormatTo to custom buffer
func (*MapFormatter) String ¶ added in v0.5.3
func (f *MapFormatter) String() string
Format to string
func (*MapFormatter) WithFn ¶ added in v0.5.3
func (f *MapFormatter) WithFn(fn func(f *MapFormatter)) *MapFormatter
WithFn for config self
func (*MapFormatter) WithIndent ¶ added in v0.5.3
func (f *MapFormatter) WithIndent(indent string) *MapFormatter
WithIndent string
type SMap ¶ added in v0.3.13
SMap is alias of map[string]string