package main import ( "log" "os" "gopkg.in/yaml.v3" ) const fmConfig = "config.yml" type GoConfig struct { Config struct { ServDir string `yaml:"serverFolder"` ServPort int `yaml:"port"` WorldFile string `yaml:"worldFile"` ServCfg string `yaml:"serverSettings"` ServExec string `yaml:"serverExec"` BackupDir string `yaml:"backupDir"` UseScreen bool `yaml:"screen"` ScreenName string `yaml:"screenName"` } `yaml:"server"` } func readCfg(factCfg string) GoConfig { //read config file (YAML) fileBytes, err := os.ReadFile(factCfg) if err != nil { log.Fatalf("Error reading config file: %v", err) } // return Struct var config GoConfig err = yaml.Unmarshal(fileBytes, &config) if err != nil { log.Fatalf("Error unmarshalling YAML file: %v", err) } return config }