From 7dd1b0eb64450b7b377264f1d1c9924c7b140b65 Mon Sep 17 00:00:00 2001 From: ayntgl <90600421+ayntgl@users.noreply.github.com> Date: Wed, 9 Feb 2022 11:46:49 +0400 Subject: [PATCH] feat: follow XDG convention for configuration file (#123) --- README.md | 2 +- util/config.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4df4773..1078b08 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ sudo mv ./discordo /usr/local/bin ### Configuration -A default configuration file is created on first start-up at `$HOME/.config/discordo.toml` on Unix, `$HOME/Library/Application Support/discordo.toml` on Darwin, and `%AppData%/discordo.toml` on Windows. +A default configuration file is created on first start-up at `$HOME/.config/discordo/config.toml` on Unix, `$HOME/Library/Application Support/discordo/config.toml` on Darwin, and `%AppData%/discordo/config.toml` on Windows. ## Disclaimer diff --git a/util/config.go b/util/config.go index 5e56534..b715715 100644 --- a/util/config.go +++ b/util/config.go @@ -2,6 +2,7 @@ package util import ( "os" + "path/filepath" "github.com/BurntSushi/toml" ) @@ -37,8 +38,13 @@ func LoadConfig() Config { if err != nil { panic(err) } + configPath += "/discordo/config.toml" + // Create a directory as well as create all of the nested directories, recursively. + err = os.MkdirAll(filepath.Dir(configPath), os.ModePerm) + if err != nil { + panic(err) + } - configPath += "/discordo.toml" c := Config{} // If the configuration file does not exist, create and write the default configuration to the file. if _, err = os.Stat(configPath); os.IsNotExist(err) {