diff options
author | Teddy Wing | 2017-06-03 19:26:05 +0200 |
---|---|---|
committer | Teddy Wing | 2017-06-03 20:53:13 +0200 |
commit | 26b206b94c95904fd85b2a3e2c63d87c817afc32 (patch) | |
tree | 574e00bdc4827d0b75a5b4e59a0803e3827b4bb3 | |
parent | e14edbd02a61fd1d999df1a4c242e30ca721046b (diff) | |
download | timetasker-26b206b94c95904fd85b2a3e2c63d87c817afc32.tar.bz2 |
Move `Config` & `loadConfig()` to config.go
Now that we have a 'config.go' file, it makes more sense for these two
to live in that file.
Change `loadConfig()` to return an error instead of printing it to the
log.
-rw-r--r-- | config.go | 22 | ||||
-rw-r--r-- | main.go | 18 |
2 files changed, 22 insertions, 18 deletions
@@ -5,9 +5,21 @@ import ( "os" "path/filepath" + "github.com/teddywing/timetasker/timetask" + + "github.com/BurntSushi/toml" "github.com/goulash/xdg" ) +type Config struct { + Auth struct { + Username string + PasswordCmd string `toml:"password_cmd"` + } + Profile timetask.Profile + Projects map[string]timetask.Project +} + const emptyConfig = `[auth] username = "" password_cmd = "" @@ -44,3 +56,13 @@ func MaybeWriteConfig() error { return nil } + +func loadConfig() error { + config = Config{} + _, err := toml.DecodeFile("config2.toml", &config) + if err != nil { + return err + } + + return nil +} @@ -9,21 +9,11 @@ import ( "github.com/teddywing/timetasker/timetask" - "github.com/BurntSushi/toml" "gopkg.in/alecthomas/kingpin.v2" ) var VERSION string = "0.1.0" -type Config struct { - Auth struct { - Username string - PasswordCmd string `toml:"password_cmd"` - } - Profile timetask.Profile - Projects map[string]timetask.Project -} - var config Config func main() { @@ -110,11 +100,3 @@ func main() { body, err = ioutil.ReadAll(resp.Body) log.Println(string(body)) } - -func loadConfig() { - config = Config{} - _, err := toml.DecodeFile("config2.toml", &config) - if err != nil { - log.Println(err) - } -} |