commit 3621c11a6166804c0fa444281cd9c0b0b2616844 Author: byte Date: Sun Mar 30 13:30:40 2025 +0200 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9ac5f6e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +modules/* +!mdules/*.csv +main diff --git a/config.json b/config.json new file mode 100644 index 0000000..b2ec947 --- /dev/null +++ b/config.json @@ -0,0 +1,19 @@ +{ + "Base_Dir": "modules", + "Modules": [ + { + "Name": "Abschnitte", + "Path": "abschnitte", + "CSVFile": "abschnitte.csv", + "Default_Language": "dt", + "Default_Variants": ["hoch"] + }, + { + "Name": "Gleise", + "Path": "gleise_zahlen", + "CSVFile": "gleise_zahlen.csv", + "Default_Variants": ["hoch"], + "Default_Language": "dt" + } + ] +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..29275ef --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module main + +go 1.24.1 + +require github.com/posener/complete v1.2.3 + +require ( + github.com/hashicorp/errwrap v1.0.0 // indirect + github.com/hashicorp/go-multierror v1.0.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e6ca257 --- /dev/null +++ b/go.sum @@ -0,0 +1,16 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= +github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/main.go b/main.go new file mode 100644 index 0000000..bf87573 --- /dev/null +++ b/main.go @@ -0,0 +1,49 @@ +package main + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "log" +) + +// 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 parsed configuration + fmt.Printf("Base Dir: %s\n", config.BaseDir) + 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) + } +}