github.com/seeker-insurance/kit@v0.0.13/maputil/maputil.go (about) 1 //Package maputil contains utility functions for working with the map[string]interface{} type. 2 //The stringmap subpackage contains utility functions for working with the map[string]string type 3 package maputil 4 5 import "sort" 6 7 //Keys returns the keys of the map as a slice. No order is guaranted. 8 func Keys(m map[string]interface{}) []string { 9 keys := make([]string, len(m)) 10 var i int 11 for k := range m { 12 keys[i] = k 13 i++ 14 } 15 return keys 16 } 17 18 //Vals returns the values of the map as a slice. No order is guaranteed. 19 func Vals(m map[string]interface{}) []interface{} { 20 vals := make([]interface{}, len(m)) 21 var i int 22 for _, v := range m { 23 vals[i] = v 24 i++ 25 } 26 return vals 27 } 28 29 //SortedKeys returns the keys of the map sorted in the usual (lexigraphic) order. 30 func SortedKeys(m map[string]interface{}) []string { 31 keys := Keys(m) 32 sort.Strings(keys) 33 return keys 34 } 35 36 //Copy returns a copy of the map 37 func Copy(m map[string]interface{}) map[string]interface{} { 38 copy := make(map[string]interface{}) 39 for k, v := range m { 40 copy[k] = v 41 } 42 return copy 43 }