import ( "bufio" "fmt" "os" "strings" ) type Resource struct { property, path string } func ReadConfig(configPath string) ([]Resource, error) { file, err := os.Open(configPath) if err != nil { return nil, err } defer file.Close() // Maps the relation between ICOMMAND and the respective file path properties := map[string]int{ "texture": 2, "mmodel": 1, "mapsound": 1, "skybox": 1, "exec": 1, "cloudlayer": 1, } resources := make([]Resource, 0) scanner := bufio.NewScanner(file) for scanner.Scan() { line := scanner.Text() fields := strings.Split(line, " ") property := fields[0] if index, ok := properties[property]; ok { resources = append(resources, Resource{property, fields[index]}) } } if err := scanner.Err(); err != nil { return nil, err } return resources, nil }