qbtrade/pkg/cache/home.go

32 lines
417 B
Go
Raw Normal View History

2024-06-27 14:42:38 +00:00
package cache
import (
"os"
"path"
)
func prepareDir(p string) string {
_, err := os.Stat(p)
if err != nil {
_ = os.Mkdir(p, 0777)
}
return p
}
func CacheDir() string {
home := HomeDir()
dir := path.Join(home, "cache")
return prepareDir(dir)
}
func HomeDir() string {
homeDir, err := os.UserHomeDir()
if err != nil {
panic(err)
}
dir := path.Join(homeDir, ".qbtrade")
return prepareDir(dir)
}