55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
|
package config
|
||
|
|
||
|
import "os"
|
||
|
import "strings"
|
||
|
import "path/filepath"
|
||
|
|
||
|
var homeDirectory string
|
||
|
var configHome string
|
||
|
var configDirs []string
|
||
|
var dataHome string
|
||
|
var cacheHome string
|
||
|
|
||
|
func init () {
|
||
|
var err error
|
||
|
homeDirectory, err = os.UserHomeDir()
|
||
|
if err != nil {
|
||
|
panic("could not get user home directory: " + err.Error())
|
||
|
}
|
||
|
|
||
|
configHome = os.Getenv("XDG_CONFIG_HOME")
|
||
|
if configHome == "" {
|
||
|
configHome = filepath.Join(homeDirectory, "/.config/")
|
||
|
}
|
||
|
|
||
|
configDirsString := os.Getenv("XDG_CONFIG_DIRS")
|
||
|
if configDirsString == "" {
|
||
|
configDirsString = "/etc/xdg/"
|
||
|
}
|
||
|
|
||
|
configDirs = append(strings.Split(configDirsString, ":"), configHome)
|
||
|
|
||
|
configHome = os.Getenv("XDG_DATA_HOME")
|
||
|
if configHome == "" {
|
||
|
configHome = filepath.Join(homeDirectory, "/.local/share/")
|
||
|
}
|
||
|
|
||
|
cacheHome = os.Getenv("XDG_CACHE_HOME")
|
||
|
if cacheHome == "" {
|
||
|
configHome = filepath.Join(homeDirectory, "/.cache/")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// DataHome returns the path to the directory where user data should be stored.
|
||
|
func DataHome (name string) (home string) {
|
||
|
home = filepath.Join(dataHome, name)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// CacheHome returns the path to the directory where cache files should be
|
||
|
// stored.
|
||
|
func CacheHome (name string) (home string) {
|
||
|
home = filepath.Join(cacheHome, name)
|
||
|
return
|
||
|
}
|