42 lines
917 B
Go
42 lines
917 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
type Config struct {
|
|
Camera struct {
|
|
RTSPURL string `yaml:"rtsp_url"`
|
|
} `yaml:"camera"`
|
|
HomeAssistant struct {
|
|
URL string `yaml:"url"`
|
|
Token string `yaml:"token"`
|
|
} `yaml:"home_assistant"`
|
|
Processing struct {
|
|
SampleInterval int `yaml:"sample_interval"`
|
|
ChangeThresholdPercent int `yaml:"change_threshold_percent"`
|
|
MaxDriftSeconds int `yaml:"max_drift_seconds"`
|
|
} `yaml:"processing"`
|
|
Logging struct {
|
|
Level string `yaml:"level"`
|
|
File string `yaml:"file"`
|
|
} `yaml:"logging"`
|
|
}
|
|
|
|
func LoadConfig(filename string) (*Config, error) {
|
|
data, err := os.ReadFile(filename)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to read config file: %w", err)
|
|
}
|
|
|
|
var config Config
|
|
if err := yaml.Unmarshal(data, &config); err != nil {
|
|
return nil, fmt.Errorf("failed to parse config file: %w", err)
|
|
}
|
|
|
|
return &config, nil
|
|
}
|