Add cache package

This commit is contained in:
Andinus 2020-03-24 20:24:47 +05:30
parent e6b0afd6b9
commit 28e35c0b0b
Signed by: andinus
GPG Key ID: B67D55D482A799FD
2 changed files with 52 additions and 0 deletions

23
cache/getdir_darwin.go vendored Normal file
View File

@ -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
}

29
cache/getdir_unix.go vendored Normal file
View File

@ -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
}