add config check
This commit is contained in:
parent
d2748259cb
commit
8a965c588a
1 changed files with 30 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue