From 957196e7bbdec54688fe8d46ef2b373e5b2514b7 Mon Sep 17 00:00:00 2001 From: dammitjeff <44111923+dammitjeff@users.noreply.github.com> Date: Tue, 12 May 2026 12:17:04 -0700 Subject: [PATCH 1/3] add fallback for config path and handle missing config file creation --- src/config/config.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/config/config.go b/src/config/config.go index 3eb49c4..df3f142 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -174,12 +174,23 @@ type HttpNotif struct { } func (cfg *Config) ReadEnv() { + // fallback in case the user adds path/.env as a directory + if info, err := os.Stat(cfg.Flags.CfgPath); err == nil && info.IsDir() { + cfg.Flags.CfgPath = filepath.Join(cfg.Flags.CfgPath, ".env") + slog.Warn("config path is a directory, using .env inside it", "path", cfg.Flags.CfgPath) + } // Try to read from .env file first err := cleanenv.ReadConfig(cfg.Flags.CfgPath, cfg) if err != nil { // If the error is because the file doesn't exist, fallback to env vars if errors.Is(err, os.ErrNotExist) { + slog.Warn("no config file found, creating empty one", "path", cfg.Flags.CfgPath) + if f, err := os.Create(cfg.Flags.CfgPath); err != nil { + slog.Warn("could not create config file", "path", cfg.Flags.CfgPath, "context", err.Error()) + } else { + f.Close() + } if err := cleanenv.ReadEnv(&cfg); err != nil { slog.Error("failed to load config from env vars", "context", err.Error()) os.Exit(1) From f4f5f91413fd545bcf123146db35039a4df038f2 Mon Sep 17 00:00:00 2001 From: dammitjeff <44111923+dammitjeff@users.noreply.github.com> Date: Tue, 12 May 2026 12:38:25 -0700 Subject: [PATCH 2/3] update config loading to read from specified config file path --- src/config/config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/config.go b/src/config/config.go index df3f142..4758aca 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -191,8 +191,8 @@ func (cfg *Config) ReadEnv() { } else { f.Close() } - if err := cleanenv.ReadEnv(&cfg); err != nil { - slog.Error("failed to load config from env vars", "context", err.Error()) + if err := cleanenv.ReadConfig(cfg.Flags.CfgPath, cfg); err != nil { + slog.Error("failed to load config file", "path", cfg.Flags.CfgPath, "context", err.Error()) os.Exit(1) } } else { From cd86b1c0aede650028538e90934d98cc291329c6 Mon Sep 17 00:00:00 2001 From: dammitjeff <44111923+dammitjeff@users.noreply.github.com> Date: Tue, 12 May 2026 12:43:41 -0700 Subject: [PATCH 3/3] fix check error on file close --- src/config/config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/config.go b/src/config/config.go index 4758aca..002cd93 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -188,8 +188,8 @@ func (cfg *Config) ReadEnv() { slog.Warn("no config file found, creating empty one", "path", cfg.Flags.CfgPath) if f, err := os.Create(cfg.Flags.CfgPath); err != nil { slog.Warn("could not create config file", "path", cfg.Flags.CfgPath, "context", err.Error()) - } else { - f.Close() + } else if err := f.Close(); err != nil { + slog.Warn("could not close config file", "path", cfg.Flags.CfgPath, "context", err.Error()) } if err := cleanenv.ReadConfig(cfg.Flags.CfgPath, cfg); err != nil { slog.Error("failed to load config file", "path", cfg.Flags.CfgPath, "context", err.Error())