package config import ( "io/ioutil" "log" yaml "gopkg.in/yaml.v3" ) var ( CONFIGFILE = "config.yaml" ) type TrackmaniaConfig struct { Host string Port int } type ApiConfig struct { Port int } type AppConfig struct { Trackmania TrackmaniaConfig Api ApiConfig } func (c *AppConfig) ReadConfig() { log.Print("Initiated the default config") // open config.yaml yamlFile, err := ioutil.ReadFile(CONFIGFILE) if err != nil { log.Fatal(err) } log.Print("Done reading yaml File") // configure config from config.yaml err = yaml.Unmarshal([]byte(yamlFile), c) if err != nil { log.Fatal(err) } log.Print("Read config from yaml File") } func LoadDefaults() AppConfig { var c AppConfig c.Trackmania.Host = "127.0.0.1" c.Trackmania.Port = 5000 c.Api.Port = 5111 return c }