-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconfig.go
57 lines (50 loc) · 1.86 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
package main
import (
"os"
"gopkg.in/yaml.v2"
)
// Config is the base configuraiton object
type Config struct {
Devices []DeviceConfig `yaml:"devices"`
Storage StorageConfig `yaml:"storage,omitempty"`
Controllers []ControllerConfig `yaml:"controllers,omitempty"`
}
// DeviceConfig holds configuration specific to the Davis Instruments device
type DeviceConfig struct {
Name string `yaml:"name"`
Type string `yaml:"type,omitempty"`
Hostname string `yaml:"hostname,omitempty"`
Port string `yaml:"port,omitempty"`
SerialDevice string `yaml:"serialdevice,omitempty"`
Baud int `yaml:"baud,omitempty"`
}
// StorageConfig holds the configuration for various storage backends.
// More than one storage backend can be used simultaneously
type StorageConfig struct {
InfluxDB InfluxDBConfig `yaml:"influxdb,omitempty"`
TimescaleDB TimescaleDBConfig `yaml:"timescaledb,omitempty"`
GRPC GRPCConfig `yaml:"grpc,omitempty"`
RESTServer RESTServerConfig `yaml:"rest,omitempty"`
APRS APRSConfig `yaml:"aprs,omitempty"`
}
// ControllerConfig holds the configuration for various controller backends.
// More than one controller backend can be used simultaneously.
type ControllerConfig struct {
Type string `yaml:"type,omitempty"`
PWSWeather PWSWeatherConfig `yaml:"pwsweather,omitempty"`
WeatherUnderground WeatherUndergroundConfig `yaml:"weatherunderground,omitempty"`
AerisWeather AerisWeatherConfig `yaml:"aerisweather,omitempty"`
}
// NewConfig creates an new config object from the given filename.
func NewConfig(filename string) (Config, error) {
cfgFile, err := os.ReadFile(filename)
if err != nil {
return Config{}, err
}
c := Config{}
err = yaml.Unmarshal(cfgFile, &c)
if err != nil {
return Config{}, err
}
return c, nil
}