diff options
author | Teddy Wing | 2017-06-03 19:42:06 +0200 |
---|---|---|
committer | Teddy Wing | 2017-06-03 20:53:14 +0200 |
commit | fa85a708dff621e4d75f19bdbd45bba5947685c0 (patch) | |
tree | 947814fce922aee3a7d298c5cca19a063ebbb68c /config.go | |
parent | 855728d1be71170a80ac4b725553b7ff67e85dc4 (diff) | |
download | timetasker-fa85a708dff621e4d75f19bdbd45bba5947685c0.tar.bz2 |
config.go: Extract config file paths to functions
Put these constructed paths into reusable functions for easier usage.
Diffstat (limited to 'config.go')
-rw-r--r-- | config.go | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -38,16 +38,24 @@ work_type = # ADD WORK TYPE ID billable = true ` +func configDir() string { + return filepath.Join(xdg.ConfigHome, "timetasker") +} + +func configFile() string { + return filepath.Join(configDir(), "config.toml") +} + func maybeWriteConfig() error { path := xdg.FindConfig("timetasker/config.toml") if path == "" { - path = filepath.Join(xdg.ConfigHome, "timetasker") + path = configDir() if _, err := os.Stat(path); os.IsNotExist(err) { os.Mkdir(path, 0700) } - config_path := filepath.Join(path, "config.toml") + config_path := configFile() err := ioutil.WriteFile(config_path, []byte(emptyConfig), 0644) if err != nil { return err |