mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
use YAML for group scneario map
This commit is contained in:
parent
174ed2dd2e
commit
c9a14bb767
3 changed files with 8 additions and 6 deletions
|
@ -22,7 +22,6 @@
|
|||
package configuration
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
@ -30,6 +29,8 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/zpatrick/go-config"
|
||||
)
|
||||
|
||||
|
@ -74,7 +75,7 @@ func InitConfig() error {
|
|||
contactName = flag.String("contact-name", "Steffen Vogel", "Name of the administrative contact")
|
||||
contactMail = flag.String("contact-mail", "svogel2@eonerc.rwth-aachen.de", "EMail of the administrative contact")
|
||||
testDataPath = flag.String("test-data-path", "database/testdata.json", "The path to the test data json file (used in test mode)")
|
||||
groupsPath = flag.String("groups-path", "configuration/groups.json", "The path to the JSON file that maps user groups to scenario IDs")
|
||||
groupsPath = flag.String("groups-path", "configuration/groups.json", "The path to a YAML file that maps user groups to scenario IDs")
|
||||
)
|
||||
flag.Parse()
|
||||
|
||||
|
@ -184,9 +185,9 @@ func ReadGroupsFile(path string) error {
|
|||
|
||||
byteValue, _ := ioutil.ReadAll(jsonFile)
|
||||
|
||||
err = json.Unmarshal(byteValue, &ScenarioGroupMap)
|
||||
err = yaml.Unmarshal(byteValue, &ScenarioGroupMap)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error unmarshalling json into ScenarioGroupMap: %v", err)
|
||||
return fmt.Errorf("error unmarshalling yaml into ScenarioGroupMap: %v", err)
|
||||
}
|
||||
|
||||
log.Println("ScenarioGroupMap", ScenarioGroupMap)
|
||||
|
|
1
go.mod
1
go.mod
|
@ -24,6 +24,7 @@ require (
|
|||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
|
||||
gopkg.in/go-playground/validator.v9 v9.30.0
|
||||
gopkg.in/ini.v1 v1.51.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
|
||||
)
|
||||
|
||||
go 1.15
|
||||
|
|
4
start.go
4
start.go
|
@ -99,13 +99,13 @@ func main() {
|
|||
|
||||
gPath, err := configuration.GlobalConfig.String("groups.path")
|
||||
if err != nil {
|
||||
log.Fatalf("Error reading path to groups JSON file: %s, aborting.", err)
|
||||
log.Fatalf("Error reading path to groups YAML file: %s, aborting.", err)
|
||||
}
|
||||
|
||||
if gPath != "" {
|
||||
err = configuration.ReadGroupsFile(gPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Error reading groups JSON file: %s, aborting.", err)
|
||||
log.Fatalf("Error reading groups YAML file: %s, aborting.", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue