discordo/internal/consts/consts.go

26 lines
592 B
Go

package consts
import (
"log/slog"
"os"
"path/filepath"
"sync"
)
const Name = "discordo"
// CacheDir returns the cache directory, creating it on first use.
var CacheDir = sync.OnceValue(func() string {
userCacheDir, err := os.UserCacheDir()
if err != nil {
userCacheDir = os.TempDir()
slog.Warn("failed to get user cache dir; falling back to temp dir", "err", err, "path", userCacheDir)
}
path := filepath.Join(userCacheDir, Name)
if err := os.MkdirAll(path, os.ModePerm); err != nil {
slog.Error("failed to create cache dir", "err", err, "path", path)
}
return path
})