package config import ( "os" "gopkg.in/yaml.v3" ) type Config struct { Serial struct { Path string `yaml:"path"` } `yaml:"serial"` Video struct { Enabled bool `yaml:"enabled"` AuxIndex int `yaml:"aux_index"` Threshold int16 `yaml:"threshold"` Command string `yaml:"command"` } `yaml:"video"` Logging struct { Enabled bool `yaml:"enabled"` Path string `yaml:"path"` } `yaml:"logging"` } func Default() Config { var c Config c.Serial.Path = "/dev/ttyS0" c.Video.Enabled = true c.Video.AuxIndex = 5 // AUX2, zero-based c.Video.Threshold = -512 c.Video.Command = "fpv-video" c.Logging.Enabled = true return c } func Load(path string) (Config, error) { config := Default() data, err := os.ReadFile(path) if err != nil { if os.IsNotExist(err) { return config, nil } return config, err } if err := yaml.Unmarshal(data, &config); err != nil { return config, err } return config, nil }