forked from otiai10/cwl.go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnamespaces.go
39 lines (35 loc) · 813 Bytes
/
namespaces.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
39
package cwl
// Namespaces ...
type Namespaces []Namespace
// New constructs "Namespaces" struct.
func (_ Namespaces) New(i interface{}) Namespaces {
dest := []Namespace{}
switch x := i.(type) {
case []interface{}:
for _, v := range x {
dest = append(dest, Namespace{}.New(v))
}
case map[string]interface{}:
for key, v := range x {
tmp := map[string]interface{}{}
tmp[key] = v
dest = append(dest, Namespace{}.New(tmp))
}
default:
dest = append(dest, Namespace{}.New(x))
}
return dest
}
// Namespace ...
type Namespace map[string]interface{}
// New constructs a Namespace from any interface.
func (_ Namespace) New(i interface{}) Namespace {
dest := Namespace{}
switch x := i.(type) {
case map[string]interface{}:
for key, v := range x {
dest[key] = v
}
}
return dest
}