-
Notifications
You must be signed in to change notification settings - Fork 14
/
support.go
78 lines (68 loc) · 2.66 KB
/
support.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package libyaml
import "encoding/json"
type Support struct {
Files []SupportFile `yaml:"files,omitempty" json:"files,omitempty" validate:"dive"`
Commands []SupportCommand `yaml:"commands,omitempty" json:"commands,omitempty" validate:"dive"`
Timeout UintString `yaml:"timeout,omitempty" json:"timeout,omitempty"`
}
type SupportFile struct {
Filename string `yaml:"filename" json:"filename" validate:"required"`
Source SchedulerContainerSource `yaml:"source" json:"source" validate:"required"`
}
type SupportCommand struct {
Filename string `yaml:"filename" json:"filename" validate:"required"`
Command []string `yaml:"command" json:"command" validate:"required"`
Source SchedulerContainerSource `yaml:"source" json:"source" validate:"required"`
}
func (s *SupportFile) UnmarshalYAML(unmarshal func(interface{}) error) error {
return s.unmarshal(unmarshal)
}
func (s *SupportFile) UnmarshalJSON(data []byte) error {
unmarshal := func(v interface{}) error {
return json.Unmarshal(data, v)
}
return s.unmarshal(unmarshal)
}
func (s *SupportFile) unmarshal(unmarshal func(interface{}) error) error {
internal := struct {
Filename string `yaml:"filename" json:"filename"`
Source SchedulerContainerSource `yaml:"source" json:"source"`
}{}
if err := unmarshal(&internal); err != nil {
return err
}
s.Filename = internal.Filename
s.Source = internal.Source
// if any are already set its probably not the "inline" style
if s.Source.SourceContainerNative != nil || s.Source.SourceContainerSwarm != nil || s.Source.SourceContainerK8s != nil {
return nil
}
return UnmarshalInline(unmarshal, &s.Source)
}
func (s *SupportCommand) UnmarshalYAML(unmarshal func(interface{}) error) error {
return s.unmarshal(unmarshal)
}
func (s *SupportCommand) UnmarshalJSON(data []byte) error {
unmarshal := func(v interface{}) error {
return json.Unmarshal(data, v)
}
return s.unmarshal(unmarshal)
}
func (s *SupportCommand) unmarshal(unmarshal func(interface{}) error) error {
internal := struct {
Filename string `yaml:"filename" json:"filename"`
Command []string `yaml:"command" json:"command"`
Source SchedulerContainerSource `yaml:"source" json:"source"`
}{}
if err := unmarshal(&internal); err != nil {
return err
}
s.Filename = internal.Filename
s.Command = internal.Command
s.Source = internal.Source
// if any are already set its probably not the "inline" style
if s.Source.SourceContainerNative != nil || s.Source.SourceContainerSwarm != nil || s.Source.SourceContainerK8s != nil {
return nil
}
return UnmarshalInline(unmarshal, &s.Source)
}