-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhints.go
64 lines (60 loc) · 1.43 KB
/
hints.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package cwl
// Hints ...
type Hints []Hint
// New constructs "Hints" struct.
func (_ Hints) New(i interface{}) Hints {
dest := []Hint{}
switch x := i.(type) {
case []interface{}:
for _, val := range x {
switch e := val.(type) {
case map[string]interface{}:
hint := Hint{}.New(e)
dest = append(dest, hint)
}
}
case map[string]interface{}:
for key, val := range x {
switch e := val.(type) {
case map[string]interface{}:
hint := Hint{}.New(e)
hint.Class = key
dest = append(dest, hint)
}
}
}
return dest
}
// Hint ...
type Hint struct {
Class string
DockerPull string // Only appears if class is "DockerRequirement"
CoresMin int // Only appears if class is "ResourceRequirement"
Envs []EnvDef // Only appears if class is "EnvVarRequirement"
FakeField string // Only appears if class is "ex:BlibberBlubberFakeRequirement"
Import string
}
// New constructs Hint from interface.
func (_ Hint) New(i interface{}) Hint {
dest := Hint{}
switch x := i.(type) {
case map[string]interface{}:
for key, val := range x {
switch key {
case "class":
dest.Class = val.(string)
case "dockerPull":
dest.DockerPull = val.(string)
case "coresMin":
dest.CoresMin = int(val.(float64))
case "fakeField":
dest.FakeField = val.(string)
case "envDef":
dest.Envs = EnvDef{}.NewList(val)
case "$import":
dest.Import = val.(string)
}
}
}
return dest
}