forked from kiali/kiali
-
Notifications
You must be signed in to change notification settings - Fork 0
/
maps.go
38 lines (30 loc) · 839 Bytes
/
maps.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package util
import "k8s.io/apimachinery/pkg/runtime/schema"
func RemoveNilValues(root interface{}) {
if mRoot, isMap := root.(map[string]interface{}); isMap {
for k, v := range mRoot {
if v == nil {
delete(mRoot, k)
}
if leaf, isLeafMap := v.(map[string]interface{}); isLeafMap {
RemoveNilValues(leaf)
}
}
}
}
func CopyStringMap(originalMap map[string]string) map[string]string {
copyMap := make(map[string]string)
if len(originalMap) == 0 {
return copyMap
}
for key, value := range originalMap {
copyMap[key] = value
}
return copyMap
}
func BuildNameNSKey(name string, namespace string) string {
return name + "." + namespace
}
func BuildNameNSTypeKey(name string, namespace string, objType schema.GroupVersionKind) string {
return BuildNameNSKey(name, namespace) + "/" + objType.String()
}