-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
57 lines (46 loc) · 1.04 KB
/
config.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
/*
* Copyright 2024 Johan Stenstam, [email protected]
*/
package main
import (
"os"
"time"
"github.com/dnstapir/tapir"
"gopkg.in/yaml.v2"
)
type Config struct {
BootTime time.Time
ApiConfig ApiConfig `yaml:"apiserver"`
LogConfig LogConfig `yaml:"log"`
TapirConfig TapirConfig `yaml:"tapir"`
StatusReceiver *StatusReceiver
PubKeyReceiver *PubKeyReceiver
MqttEngine *tapir.MqttEngine
}
type TapirConfig struct {
MqttConfig MqttConfig `yaml:"mqtt"`
}
type MqttConfig struct {
ClientID string `yaml:"client_id"`
Server string `yaml:"server"`
QoS int `yaml:"qos"`
}
type ApiConfig struct {
Address string `yaml:"address"`
Key string `yaml:"key"`
}
type LogConfig struct {
File string `yaml:"file"`
}
func LoadConfig(filename string) (*Config, error) {
data, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
var config Config
if err := yaml.Unmarshal(data, &config); err != nil {
return nil, err
}
config.BootTime = time.Now()
return &config, nil
}