diff options
author | Andinus <andinus@nand.sh> | 2020-03-24 20:24:47 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2020-03-24 20:24:47 +0530 |
commit | 28e35c0b0b996e17bd94a5b9e78fda90086ba85e (patch) | |
tree | 5721c5e2bd7ff9fe3d509d599ab34e735871fbf6 | |
parent | e6b0afd6b97b2402e218583e7c22551b383712df (diff) | |
download | cetus-28e35c0b0b996e17bd94a5b9e78fda90086ba85e.tar.gz |
Add cache package
-rw-r--r-- | cache/getdir_darwin.go | 23 | ||||
-rw-r--r-- | cache/getdir_unix.go | 29 |
2 files changed, 52 insertions, 0 deletions
diff --git a/cache/getdir_darwin.go b/cache/getdir_darwin.go new file mode 100644 index 0000000..fc47e7e --- /dev/null +++ b/cache/getdir_darwin.go @@ -0,0 +1,23 @@ +// +build darwin + +package cache + +import ( + "fmt" + "os" +) + +// GetDir returns cetus cache directory. Default cache directory on +// macOS is $HOME/Library/Caches. +func GetDir() string { + cacheDir = fmt.Sprintf("%s/%s/%s", + os.Getenv("HOME"), + "Library", + "Caches") + + // Cetus cache directory is cacheDir/cetus + cetusCacheDir = fmt.Sprintf("%s/%s", cacheDir, + "cetus") + + return cetusCacheDir +} diff --git a/cache/getdir_unix.go b/cache/getdir_unix.go new file mode 100644 index 0000000..b1358d7 --- /dev/null +++ b/cache/getdir_unix.go @@ -0,0 +1,29 @@ +// +build linux netbsd openbsd freebsd dragonfly + +package cache + +import ( + "fmt" + "os" +) + +// GetDir returns cetus cache directory. Check if the user has set +// CETUS_CACHE_DIR, if not then check if XDG_CACHE_HOME is set & if +// that is not set then assume it to be the default value which is +// $HOME/.cache according to XDG Base Directory Specification. +func GetDir() string { + cacheDir := os.Getenv("CETUS_CACHE_DIR") + if len(cacheDir) == 0 { + cacheDir = os.Getenv("XDG_CACHE_HOME") + } + if len(cacheDir) == 0 { + cacheDir = fmt.Sprintf("%s/%s", os.Getenv("HOME"), + ".cache") + } + + // Cetus cache directory is cacheDir/cetus. + cetusCacheDir = fmt.Sprintf("%s/%s", cacheDir, + "cetus") + + return cetusCacheDir +} |