fix: only panic if the error is other than a missing config file

This commit is contained in:
Derrick Hammer 2023-04-30 02:14:44 -04:00
parent 241db4deb6
commit 6e0ec8aaf9
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 7 additions and 1 deletions

View File

@ -34,7 +34,13 @@ func Init() {
err = viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("Fatal error config file: %s \n", err))
if errors.As(err, &viper.ConfigFileNotFoundError{}) {
// Config file not found, this is not an error.
fmt.Println("Config file not found, using default settings.")
} else {
// Other error, panic.
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
}
}