78 lines
1.6 KiB
Go
78 lines
1.6 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
type Config struct {
|
|
Server ServerConfig `yaml:"server"`
|
|
Devices DevicesConfig `yaml:"devices"`
|
|
Weather WeatherConfig `yaml:"weather"`
|
|
Location LocationConfig `yaml:"location"`
|
|
}
|
|
|
|
type ServerConfig struct {
|
|
Host string `yaml:"host"`
|
|
Port int `yaml:"port"`
|
|
}
|
|
|
|
type DevicesConfig struct {
|
|
WebSwitch WebSwitchConfig `yaml:"webswitch"`
|
|
PowerGenius PowerGeniusConfig `yaml:"power_genius"`
|
|
TunerGenius TunerGeniusConfig `yaml:"tuner_genius"`
|
|
AntennaGenius AntennaGeniusConfig `yaml:"antenna_genius"`
|
|
RotatorGenius RotatorGeniusConfig `yaml:"rotator_genius"`
|
|
}
|
|
|
|
type WebSwitchConfig struct {
|
|
Host string `yaml:"host"`
|
|
}
|
|
|
|
type PowerGeniusConfig struct {
|
|
Host string `yaml:"host"`
|
|
Port int `yaml:"port"`
|
|
}
|
|
|
|
type TunerGeniusConfig struct {
|
|
Host string `yaml:"host"`
|
|
Port int `yaml:"port"`
|
|
}
|
|
|
|
type AntennaGeniusConfig struct {
|
|
Host string `yaml:"host"`
|
|
Port int `yaml:"port"`
|
|
}
|
|
|
|
type RotatorGeniusConfig struct {
|
|
Host string `yaml:"host"`
|
|
Port int `yaml:"port"`
|
|
}
|
|
|
|
type WeatherConfig struct {
|
|
OpenWeatherMapAPIKey string `yaml:"openweathermap_api_key"`
|
|
LightningEnabled bool `yaml:"lightning_enabled"`
|
|
}
|
|
|
|
type LocationConfig struct {
|
|
Latitude float64 `yaml:"latitude"`
|
|
Longitude float64 `yaml:"longitude"`
|
|
Callsign string `yaml:"callsign"`
|
|
}
|
|
|
|
func Load(path string) (*Config, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to read config file: %w", err)
|
|
}
|
|
|
|
var cfg Config
|
|
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
|
return nil, fmt.Errorf("failed to parse config file: %w", err)
|
|
}
|
|
|
|
return &cfg, nil
|
|
}
|