package main import ( "encoding/csv" "encoding/json" "fmt" "io/ioutil" "log" "os" "strings" ) // Config represents the structure of the config.json file. type Config struct { BaseDir string `json:"Base_Dir"` Modules []Module `json:"Modules"` } // Module represents a module entry in the config.json file. type Module struct { Name string `json:"Name"` Path string `json:"Path"` CSVFile string `json:"CSVFile"` DefaultLanguage string `json:"Default_Language"` DefaultVariants []string `json:"Default_Variants"` } func main() { // Open the config.json file configFilePath := "config.json" data, err := ioutil.ReadFile(configFilePath) if err != nil { log.Fatalf("Error reading file: %v", err) } // Parse the JSON data into a Config struct var config Config err = json.Unmarshal(data, &config) if err != nil { log.Fatalf("Error parsing JSON: %v", err) } // Print the display texts of all modules as a comma-separated list fmt.Println("Display Texts of Modules:") for _, module := range config.Modules { displayTexts := []string{} csvFilePath := config.BaseDir + "/" + module.CSVFile // Open and read the CSV file csvFile, err := os.Open(csvFilePath) if err != nil { log.Fatalf("Error opening CSV file %s: %v", csvFilePath, err) } defer csvFile.Close() reader := csv.NewReader(csvFile) records, err := reader.ReadAll() if err != nil { log.Fatalf("Error reading CSV file %s: %v", csvFilePath, err) } // Ignore the first line if len(records) > 1 { records = records[1:] } for _, record := range records { displayTexts = append(displayTexts, record[1]) // Assuming the display text is in the second column (index 1) } fmt.Printf("- Module Name: %s (%s)\n", module.Name, commaSeparated(displayTexts)) } } // Helper function to join a slice of strings with commas func commaSeparated(slice []string) string { return fmt.Sprintf("[%s]", strings.Join(slice, ", ")) }