package main import ( "errors" "fmt" "log" "os" "gopkg.in/yaml.v3" ) func readCfg(factCfg string) UsrConfig { //read config file (YAML) fileBytes, err := os.ReadFile(factCfg) if err != nil { log.Fatalf("Error reading config file: %v", err) } // return Struct var config UsrConfig err = yaml.Unmarshal(fileBytes, &config) if err != nil { log.Fatalf("Error unmarshalling YAML file: %v", err) } return config } func isItReal(path string) bool { //check if path exists if _, err := os.Stat(path); err == nil { return true } else if errors.Is(err, os.ErrNotExist) { return false } else { return false } } func verifyConfig(config UsrConfig) bool { // check each file/dir to see if it exists if !isItReal(config.Server.ServDir) { //check for Server directory fmt.Printf("PATH NOT FOUND: %s", config.Server.ServDir) return false } if !isItReal(config.Server.WorldFile) { // check for world file fmt.Printf("PATH NOT FOUND: %s", config.Server.WorldFile) return false } if !isItReal(config.Server.ServCfg) { // check for server config fmt.Printf("PATH NOT FOUND: %s", config.Server.ServCfg) return false } if !isItReal(config.Server.ServExec) { // check for server exec file to lanch server fmt.Printf("PATH NOT FOUND: %s", config.Server.ServExec) return false } if !isItReal(config.Factoryman.BackupDir) { // check for backup directory fmt.Printf("PATH NOT FOUND: %s", config.Factoryman.BackupDir) return false } if config.Factoryman.ApiToken == "" || config.Factoryman.UserName == "" { fmt.Printf("API Token/Username not set (to download mods add api token and username to config)") } return true }