push stuff
This commit is contained in:
parent
3621c11a61
commit
b9bebe7dd3
1 changed files with 43 additions and 14 deletions
57
main.go
57
main.go
|
@ -1,25 +1,28 @@
|
|||
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"`
|
||||
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"`
|
||||
Name string `json:"Name"`
|
||||
Path string `json:"Path"`
|
||||
CSVFile string `json:"CSVFile"`
|
||||
DefaultLanguage string `json:"Default_Language"`
|
||||
DefaultVariants []string `json:"Default_Variants"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -37,13 +40,39 @@ func main() {
|
|||
log.Fatalf("Error parsing JSON: %v", err)
|
||||
}
|
||||
|
||||
// Print the parsed configuration
|
||||
fmt.Printf("Base Dir: %s\n", config.BaseDir)
|
||||
// Print the display texts of all modules as a comma-separated list
|
||||
fmt.Println("Display Texts of Modules:")
|
||||
for _, module := range config.Modules {
|
||||
fmt.Printf("Module Name: %s\n", module.Name)
|
||||
fmt.Printf(" Path: %s\n", module.Path)
|
||||
fmt.Printf(" CSV File: %s\n", module.CSVFile)
|
||||
fmt.Printf(" Default Language: %s\n", module.DefaultLanguage)
|
||||
fmt.Printf(" Default Variants: %v\n", module.DefaultVariants)
|
||||
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, ", "))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue