From fa85a708dff621e4d75f19bdbd45bba5947685c0 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 3 Jun 2017 19:42:06 +0200 Subject: config.go: Extract config file paths to functions Put these constructed paths into reusable functions for easier usage. --- config.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'config.go') diff --git a/config.go b/config.go index e2d2f94..43f7689 100644 --- a/config.go +++ b/config.go @@ -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 -- cgit v1.2.3