dashboard of nationalrail train times
at main 36 lines 658 B view raw
1package main 2 3import ( 4 "fmt" 5 "os" 6 7 "gopkg.in/yaml.v3" 8) 9 10type Config struct { 11 Server struct { 12 Port int `yaml:"port"` 13 RefreshInterval int `yaml:"refresh_interval"` 14 } `yaml:"server"` 15 Stations []Station `yaml:"stations"` 16} 17 18type Station struct { 19 Name string `yaml:"name"` 20 Code string `yaml:"code"` 21} 22 23func LoadConfig(filename string) (*Config, error) { 24 data, err := os.ReadFile(filename) 25 if err != nil { 26 return nil, fmt.Errorf("failed to read config file: %w", err) 27 } 28 29 var config Config 30 err = yaml.Unmarshal(data, &config) 31 if err != nil { 32 return nil, fmt.Errorf("failed to parse config file: %w", err) 33 } 34 35 return &config, nil 36}