From 4b0ce1df5f27ca6add010b713b173fb962cf5cb4 Mon Sep 17 00:00:00 2001 From: juancwu Date: Wed, 28 Jan 2026 16:23:42 +0000 Subject: [PATCH] feat: store config file path in struct --- internal/config/config.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 0b4a52f..d284295 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -9,6 +9,8 @@ import ( type Config struct { ForgejoInstanceURL string `json:"forgejo_instance_url"` + + filepath string `json:"-"` } // Load tries to load a saved configuration. @@ -22,7 +24,7 @@ func Load(path string) (*Config, error) { } if _, err := os.Stat(path); os.IsNotExist(err) { - return &Config{}, nil + return &Config{filepath: path}, nil } fileData, err := os.ReadFile(path) @@ -35,6 +37,7 @@ func Load(path string) (*Config, error) { if err != nil { return nil, fmt.Errorf("failed to unmarshal config file: %w", err) } + cfg.filepath = path return &cfg, nil } @@ -42,10 +45,7 @@ func Load(path string) (*Config, error) { func (cfg *Config) Save(path string) error { var err error if path == "" { - path, err = getUserConfigDir() - if err != nil { - return fmt.Errorf("failed to save config: %w", err) - } + path = cfg.filepath } fileData, err := json.MarshalIndent(cfg, "", " ")