blob: 4698998b15dfde7206639399d1fcce3d8eae570b (
plain)
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 main
import (
"encoding/json"
"os"
)
type Config struct {
NodeID []byte `json:"nodeID"`
Name string `json:"name"`
ShortName string `json:"shortName"`
DefaultHops uint32 `json:"defaultHops"`
MaxHops uint32 `json:"maxHops"`
NodeBroadcastInterval float64 `json:"nodeBroadcastInterval"`
X25519Key []byte `json:"x25519Key"`
Channels []struct {
Name string `json:"name"`
PSK []byte `json:"psk"`
} `json:"channels"`
Position struct {
BroadcastInterval float64 `json:"broadcastInterval"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Altitude float64 `json:"altitude"`
} `json:"position"`
DeviceMetrics struct {
BroadcastInterval float64 `json:"broadcastInterval"`
UPSAddress string `json:"upsAddress"`
} `json:"deviceMetrics"`
KavaModem struct {
Address string `json:"address"`
} `json:"kavaModem"`
MqttIf struct {
Address string `json:"address"`
Username string `json:"username"`
Password string `json:"password"`
ClientID string `json:"clientId"`
Root string `json:"root"`
} `json:"mqttIf"`
}
func ReadConfig(filename string) (*Config, error) {
cfg := Config{}
f, err := os.Open(filename)
if err != nil {
return nil, err
}
dec := json.NewDecoder(f)
if err := dec.Decode(&cfg); err != nil {
return nil, err
}
return &cfg, nil
}
|