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{ Trackmania: TrackmaniaConfig{ Host: "127.0.0.1", Port: 5000, }, Api: ApiConfig{ Port: 5111, }, } return c }