From 7010ef25c90272b81eff2f37a3ca7ac5afd53b69 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 11 Mar 2017 14:26:02 +0100 Subject: Add main.go with configuration Set up a configuration object which gets read from a YAML config file. Currently using an uncommitted test file that looks like this (with some data filled in: auth: username: password_cmd: fields: person_id: clients: - id: name: projects: - id: name: modules: - id: name: tasks: - id: name: work_types: - id: name: The program just outputs the config object so I can see whether it's working. The data will then be used to associate ids for time submission. --- main.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 main.go (limited to 'main.go') diff --git a/main.go b/main.go new file mode 100644 index 0000000..ba853e1 --- /dev/null +++ b/main.go @@ -0,0 +1,49 @@ +package main + +import ( + "io/ioutil" + "log" + + "gopkg.in/yaml.v1" +) + +type Config struct { + Auth struct { + Username string + PasswordCmd string `yaml:"password_cmd"` + } + Fields struct { + PersonID uint `yaml:"person_id"` + Clients []struct { + ID uint + Name string + Projects []struct { + ID uint + Name string + Modules []struct { + ID uint + Name string + } + Tasks []struct { + ID uint + Name string + } + WorkTypes []struct { + ID uint + Name string + } `yaml:"work_types"` + } + } + } +} + +func main() { + config_str, err := ioutil.ReadFile("config.yml") + config := Config{} + err = yaml.Unmarshal(config_str, &config) + if err != nil { + log.Println(err) + } + + log.Printf("%+v", config) +} -- cgit v1.2.3