refactor: set default options starting with core.post-upload-limi, and save the config when none exists

This commit is contained in:
Derrick Hammer 2024-01-14 23:54:01 -05:00
parent 492bd5b9de
commit 9ebdeb74c6
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 10 additions and 0 deletions

View File

@ -25,10 +25,16 @@ func Init(logger *zap.Logger) error {
viper.SetEnvPrefix("LUME_WEB_PORTAL")
viper.AutomaticEnv()
defaults()
err := viper.ReadInConfig()
if err != nil {
if errors.As(err, &viper.ConfigFileNotFoundError{}) {
logger.Info("Config file not found, using default settings.")
err := viper.SafeWriteConfig()
if err != nil {
return err
}
return nil
}
return err
@ -36,3 +42,7 @@ func Init(logger *zap.Logger) error {
return nil
}
func defaults() {
viper.SetDefault("core.post-upload-limit", 1024*1024*1000)
}