add config check

This commit is contained in:
Adora Laura Kalb 2024-07-26 10:54:50 +02:00
parent d2748259cb
commit 8a965c588a
Signed by: adoralaura
SSH key fingerprint: SHA256:3XrkbR8ikAZJVtYfaUliX1MhmJYVAe/ocIb/MiDHBJ8

View file

@ -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)
}
}