From 8a965c588a064d1ec4eb761254f5782708a8236b Mon Sep 17 00:00:00 2001 From: Adora Laura Kalb Date: Fri, 26 Jul 2024 10:54:50 +0200 Subject: [PATCH] add config check --- internal/configuration/configuration.go | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/internal/configuration/configuration.go b/internal/configuration/configuration.go index 01bdf3d..23ad512 100644 --- a/internal/configuration/configuration.go +++ b/internal/configuration/configuration.go @@ -48,8 +48,38 @@ func (c Config) LoadFromDisk() error { return fmt.Errorf("failed to unmarshal config file: %w", err) } + c.checkConfig() + slog.Debug("successfully read config file", "path", ConfigFile) return nil } + +func (c Config) checkConfig() { + failed := false + if c.ApiEndpoint == "" { + slog.Error("[CONFIG] api_endpoint must not be empty") + failed = true + } + + if c.ApiKey == "" { + slog.Error("[CONFIG] api_key must not be empty") + failed = true + } + + if c.AdminEmail == "" { + slog.Error("[CONFIG] admin_email must not be empty") + failed = true + } + + if len(c.MailPrefixes) < 1 { + slog.Error("[CONFIG] mail_prefixes must have at least one entry") + failed = true + } + + if failed { + slog.Error("[CONFIG] Application can't start until above errors are fixed.") + os.Exit(1) + } +}