From b47d3326f6175a3fb0b997a20b3b1daa3dc9156f Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Sat, 13 Jan 2018 01:22:02 +0000 Subject: added yaml config file --- config.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 config.go (limited to 'config.go') diff --git a/config.go b/config.go new file mode 100644 index 0000000..c71d287 --- /dev/null +++ b/config.go @@ -0,0 +1,43 @@ +package main + +import ( + "gopkg.in/yaml.v2" + "io/ioutil" + "log" +) + +type CompCfg struct { + Name string `yaml:"Name"` + URL string `yaml:"URL"` +} + +type Suite struct { + Name string `yaml:"Name"` + Components []CompCfg `yaml:"Components"` +} + +type ReleaseCfg struct { + Release string `yaml:"Release"` + RepoURL string `yaml:"RepoURL"` + Suites []Suite `yaml:"Suites"` +} + +type PkgwebCfg struct { + PkgSets []ReleaseCfg `yaml:"PkgSets"` +} + +func readConfig(fname string) *PkgwebCfg { + + data, err := ioutil.ReadFile(fname) + if err != nil { + log.Fatal("Error while reading file: ", err) + } + + cfg := new(PkgwebCfg) + + err = yaml.Unmarshal(data, cfg) + if err != nil { + log.Fatal("Error while reading configuration: ", err) + } + return cfg +} -- cgit v1.2.3