Documentation ¶
Overview ¶
package stringmap contains utilities to handle common map operations
Index ¶
- func FromJson(j []byte) (out map[string]interface{}, err error)
- func FromJsonFile(f string) (out map[string]interface{}, err error)
- func GetBool(m map[string]interface{}, key string) (bool, bool)
- func GetJsonFloat(m map[string]interface{}, key string) (float64, bool)
- func GetJsonInt(m map[string]interface{}, key string) (int, bool)
- func GetString(m map[string]interface{}, key string) (string, bool)
- func JoinStrings(m map[string]string, kvSep string, itemSep string) (ret string)
- func Range(m interface{}, f func(key string, val interface{}) bool)
- func SortedKeys(i interface{}) []string
- func ToStringStringMap(in map[string]interface{}) map[string]string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromJson ¶ added in v0.14.0
Converts a json map to a stringmap Integers come through as float64, so must be converted to int to be used
func FromJsonFile ¶ added in v0.14.0
func GetBool ¶ added in v0.14.0
GetBool gets a boolean out of a map of interfaces keyed by a string. Returns the bool and true if found, or false and false if not, or the found item was not a bool.
func GetJsonFloat ¶
GetJsonFloat gets a float64 out of a map of interfaces that were unmarshalled from json. Json unmarshalling creates json numbers, and these have to be coerced into integers or floats. Returns an int and true if found, and a zero and false if not, or the found item was not a coercible number.
func GetJsonInt ¶
GetJsonInt gets an integer out of a map of interfaces that were unmarshalled from json. Json unmarshalling creates json numbers, and these have to be coerced into integers or floats. Returns an int and true if found, and a zero and false if not, or the found item was not a coercible number.
func GetString ¶
GetString gets a string out of a map of interfaces keyed by a string. Returns the string and true if found, or an empty string and false if not, or the found item was not a string.
func JoinStrings ¶ added in v0.3.1
JoinStrings will join a map[string]string with kvSep in between each key and value, and itemSep in between each group of those
func Range ¶
Range is a convenience method to range over any map that uses strings as keys in a predictable order from lowest to highest. It uses a similar Range type function to the sync.StdMap.Range function.
func SortedKeys ¶
func SortedKeys(i interface{}) []string
SortedKeys returns the keys of any map that uses strings as keys, sorted alphabetically. Note that even though we are using reflection here, this process is only slightly slower compared to not using reflection, so feel free to use it in all situations.
Example ¶
m := map[string]int{ "One": 1, "Two": 2, "Three": 3, } k := SortedKeys(m) fmt.Print(k)
Output: [One Three Two]
func ToStringStringMap ¶ added in v0.14.0
ToStringStringMap converts a map[string]interface{} to map[string]string. Any items in the incoming map that are not strings are ignored.
Types ¶
This section is empty.