diff options
author | Teddy Wing | 2017-03-11 14:26:02 +0100 |
---|---|---|
committer | Teddy Wing | 2017-03-11 14:26:35 +0100 |
commit | 7010ef25c90272b81eff2f37a3ca7ac5afd53b69 (patch) | |
tree | 47599f3ca657b01e1cd815890a2d20b3b75b8c22 | |
parent | 77db7d2f16fb40d4e0654cae8669eb2fac059bbb (diff) | |
download | timetasker-7010ef25c90272b81eff2f37a3ca7ac5afd53b69.tar.bz2 |
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.
-rw-r--r-- | main.go | 49 |
1 files changed, 49 insertions, 0 deletions
@@ -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) +} |