/
models.go
53 lines (45 loc) · 1.39 KB
/
models.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
package conf
import "encoding/json"
// SpoonConfig is the definition of the json config structure
type SpoonConfig struct {
BasePath string `json:"base_path"`
Agents []SpoonConfigAgent `json:"agents"`
Sink SpoonConfigSink `json:"sink"`
}
type internalSpoonConfigAgent struct {
Enabled bool `json:"enabled"`
Type string `json:"type"`
Interval float32 `json:"interval"`
Path string `json:"path"`
SettingsRaw json.RawMessage `json:"settings,omitempty"`
Settings interface{} `json:"-"`
}
// SpoonConfigAgent is a sub structure of SpoonConfig
type SpoonConfigAgent struct {
internalSpoonConfigAgent
}
func (s *SpoonConfigAgent) MarshalJSON() ([]byte, error) {
b, err := json.Marshal(s.Settings)
if err != nil {
return nil, err
}
s.SettingsRaw = json.RawMessage(b)
return json.Marshal(s.internalSpoonConfigAgent)
}
type internalSpoonConfigSink struct {
Type string `json:"type"`
SettingsRaw json.RawMessage `json:"settings,omitempty"`
Settings interface{} `json:"-"`
}
// SpoonConfigSink is a sub structure of SpoonConfig
type SpoonConfigSink struct {
internalSpoonConfigSink
}
func (s *SpoonConfigSink) MarshalJSON() ([]byte, error) {
b, err := json.Marshal(s.Settings)
if err != nil {
return nil, err
}
s.SettingsRaw = json.RawMessage(b)
return json.Marshal(s.internalSpoonConfigSink)
}