config: use os.UserConfigDir

This commit is contained in:
Simon Ser 2022-05-24 21:20:13 +02:00
parent e1b5ccefb0
commit 9f72034eb3
1 changed files with 3 additions and 8 deletions

View File

@ -1,19 +1,14 @@
package config package config
import ( import (
"errors"
"os" "os"
"path/filepath" "path/filepath"
) )
func Path(filename string) (string, error) { func Path(filename string) (string, error) {
configHome := os.Getenv("XDG_CONFIG_HOME") configHome, err := os.UserConfigDir()
if configHome == "" { if err != nil {
home := os.Getenv("HOME") return "", err
if home == "" {
return "", errors.New("HOME not set")
}
configHome = filepath.Join(home, ".config")
} }
p := filepath.Join(configHome, "hydroxide", filename) p := filepath.Join(configHome, "hydroxide", filename)