/
marshaler.go
96 lines (90 loc) · 2.61 KB
/
marshaler.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package config
func (c Config) MarshalYAML() (interface{}, error) {
return configRead{
Version: &c.Version,
MqttClients: func() mqttClientConfigReadMap {
mqttClients := make(mqttClientConfigReadMap, len(c.MqttClients))
for _, c := range c.MqttClients {
mqttClients[c.Name()] = c.convertToRead()
}
return mqttClients
}(),
InfluxClients: func() influxClientConfigReadMap {
influxClients := make(influxClientConfigReadMap, len(c.InfluxClients))
for _, c := range c.InfluxClients {
influxClients[c.Name()] = c.convertToRead()
}
return influxClients
}(),
Converters: func() converterConfigReadMap {
converters := make(converterConfigReadMap, len(c.Converters))
for _, c := range c.Converters {
converters[c.Name()] = c.convertToRead()
}
return converters
}(),
HttpServer: func() *httpServerConfigRead {
if !c.HttpServer.Enabled() {
return nil
}
r := c.HttpServer.convertToRead()
return &r
}(),
Statistics: func() *statisticsConfigRead {
if !c.Statistics.Enabled() {
return nil
}
r := c.Statistics.convertToRead()
return &r
}(),
LogConfig: &c.LogConfig,
LogWorkerStart: &c.LogWorkerStart,
LogMqttDebug: &c.LogMqttDebug,
}, nil
}
func (c MqttClientConfig) convertToRead() mqttClientConfigRead {
return mqttClientConfigRead{
Broker: c.broker,
User: c.user,
Password: c.password,
ClientId: c.clientId,
Qos: &c.qos,
AvailabilityTopic: &c.availabilityTopic,
TopicPrefix: c.topicPrefix,
LogMessages: &c.logMessages,
}
}
func (c InfluxClientConfig) convertToRead() influxClientConfigRead {
return influxClientConfigRead{
Address: c.address,
User: c.user,
Password: c.password,
Database: c.database,
WriteInterval: c.writeInterval.String(),
TimePrecision: c.timePrecision.String(),
LogLineProtocol: &c.logLineProtocol,
}
}
func (c ConverterConfig) convertToRead() converterConfigRead {
return converterConfigRead{
Implementation: c.implementation,
TargetMeasurement: c.targetMeasurement,
MqttTopics: c.mqttTopics,
MqttClients: c.mqttClients,
LogHandleOnce: &c.logHandleOnce,
}
}
func (c HttpServerConfig) convertToRead() httpServerConfigRead {
return httpServerConfigRead{
Bind: c.bind,
Port: &c.port,
LogRequests: &c.logRequests,
}
}
func (c StatisticsConfig) convertToRead() statisticsConfigRead {
return statisticsConfigRead{
Enabled: &c.enabled,
HistoryResolution: c.HistoryResolution().String(),
HistoryMaxAge: c.HistoryMaxAge().String(),
}
}