From aa27aea627e99c7a8c526f67faa2c60bdf938cfe Mon Sep 17 00:00:00 2001 From: ayn2op Date: Mon, 20 Jul 2026 21:19:10 -0400 Subject: [PATCH] refactor(config): cache config directory --- internal/config/config.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 83b11eb..1a3b18b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -6,6 +6,7 @@ import ( "log/slog" "os" "path/filepath" + "sync" "unicode/utf8" "github.com/BurntSushi/toml" @@ -135,14 +136,17 @@ type ( //go:embed config.toml var defaultCfg []byte -func DefaultPath() string { +var dir = sync.OnceValue(func() string { path, err := os.UserConfigDir() if err != nil { slog.Info("user config dir cannot be determined; falling back to the current dir", "err", err) path = "." } + return filepath.Join(path, consts.Name) +}) - return filepath.Join(path, consts.Name, fileName) +func DefaultPath() string { + return filepath.Join(dir(), fileName) } // Load reads the configuration file and parses it.