From 5bcd1243612d28068455d49df1a015a8f4c37068 Mon Sep 17 00:00:00 2001 From: ayn2op Date: Thu, 21 May 2026 20:34:32 -0400 Subject: [PATCH] refactor(config): flatten config-file load into a switch --- internal/config/config.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 17cbe8a..f0f3af6 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -146,20 +146,13 @@ func Load(path string) (*Config, error) { } file, err := os.Open(path) - if os.IsNotExist(err) { - slog.Info( - "config file does not exist, falling back to the default config", - "path", - path, - "err", - err, - ) - } else { - if err != nil { - return nil, fmt.Errorf("failed to open config file: %w", err) - } + switch { + case os.IsNotExist(err): + slog.Info("config file does not exist, falling back to the default config", "path", path, "err", err) + case err != nil: + return nil, fmt.Errorf("failed to open config file: %w", err) + default: defer file.Close() - if _, err := toml.NewDecoder(file).Decode(&cfg); err != nil { return nil, fmt.Errorf("failed to decode config: %w", err) }