10 examples of 'golang map keys' in Go

Every line of 'golang map keys' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
104func keyInMap(k string, m map[string]interface{}) bool {
105 if _, ok := m[k]; ok {
106 return true
107 }
108 return false
109}
19func MapIntKeys(data map[int]int) []int {
20 keys := make([]int, 0, len(data))
21 for key, _ := range data {
22 keys = append(keys, key)
23 }
24 return keys
25}
359func getMapKeys(m map[string]interface{}) []string {
360 keys := make([]string, 0, len(m))
361 for k := range m {
362 keys = append(keys, k)
363 }
364 return keys
365}
602func keysFromMap(m map[string]string) []string {
603 labelKeys := make([]string, len(m))
604 i := 0
605 for k := range m {
606 labelKeys[i] = k
607 i++
608 }
609 return labelKeys
610}
235func (p Params) Map(k string) map[string]interface{} {
236 val, _ := p[k].(map[string]interface{})
237 return val
238}
71func mapify(l []interface{}, key string) map[interface{}]interface{} {
72 m := make(map[interface{}]interface{})
73
74 for _, v := range l {
75 if typeof(v) != Map {
76 return nil
77 }
78 o := v.(map[interface{}]interface{})
79 k, ok := o[key]
80 if !ok {
81 return nil
82 }
83 m[k] = v
84 }
85
86 return m
87}
51func getMapKeysVals(m map[string]interface{}) (keys []string, vals []interface{}, err error) {
52 // If invalid map, return error now.
53 if m == nil {
54 return nil, nil, errors.New("Input map cannot be nil")
55 }
56
57 // Create keys and vals slices with appropriate length/capacity.
58 n := len(m)
59 keys = make([]string, n)
60 vals = make([]interface{}, n)
61
62 // Iterate through map keys/vals and place into slices.
63 i := 0
64 for key, val := range m {
65 keys[i] = key
66 vals[i] = val
67 i++
68 }
69
70 // Return final keys/vals with success.
71 return keys, vals, nil
72}
102func (v *BaseApiParserVisitor) VisitMapType(ctx *MapTypeContext) interface{} {
103 return v.VisitChildren(ctx)
104}
10func Keys(mapData map[string]interface{}) []string {
11 keys := []string{}
12 for key := range mapData {
13 keys = append(keys, key)
14 }
15 return keys
16}
768func (m *Expr_CreateStruct_Entry) GetMapKey() *Expr {
769 if x, ok := m.GetKeyKind().(*Expr_CreateStruct_Entry_MapKey); ok {
770 return x.MapKey
771 }
772 return nil
773}

Related snippets