mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
check if groups file exists
This commit is contained in:
parent
34e6e61dc2
commit
174ed2dd2e
1 changed files with 28 additions and 17 deletions
|
@ -170,22 +170,33 @@ func InitConfig() error {
|
||||||
|
|
||||||
func ReadGroupsFile(path string) error {
|
func ReadGroupsFile(path string) error {
|
||||||
|
|
||||||
jsonFile, err := os.Open(path)
|
_, err := os.Stat(path)
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error opening json file for groups: %v", err)
|
if err == nil {
|
||||||
|
|
||||||
|
jsonFile, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error opening json file for groups: %v", err)
|
||||||
|
}
|
||||||
|
log.Println("Successfully opened json groups file", path)
|
||||||
|
|
||||||
|
defer jsonFile.Close()
|
||||||
|
|
||||||
|
byteValue, _ := ioutil.ReadAll(jsonFile)
|
||||||
|
|
||||||
|
err = json.Unmarshal(byteValue, &ScenarioGroupMap)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error unmarshalling json into ScenarioGroupMap: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("ScenarioGroupMap", ScenarioGroupMap)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
} else if os.IsNotExist(err) {
|
||||||
|
log.Println("File does not exist, no goups/scenarios mapping created:", path)
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
log.Println("Something is wrong with this file path:", path)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
log.Println("Successfully opened json groups file", path)
|
|
||||||
|
|
||||||
defer jsonFile.Close()
|
|
||||||
|
|
||||||
byteValue, _ := ioutil.ReadAll(jsonFile)
|
|
||||||
|
|
||||||
err = json.Unmarshal(byteValue, &ScenarioGroupMap)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error unmarshalling json into ScenarioGroupMap: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Println("ScenarioGroupMap", ScenarioGroupMap)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue