first
This commit is contained in:
78
internal/config/config.go
Normal file
78
internal/config/config.go
Normal file
@@ -0,0 +1,78 @@
|
||||
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"`
|
||||
IDNumber int `yaml:"id_number"`
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user