fix: use logger and return errors

This commit is contained in:
Derrick Hammer 2024-01-11 23:23:22 -05:00
parent a54341dd68
commit b8572ea712
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 6 additions and 6 deletions

View File

@ -2,7 +2,6 @@ package config
import (
"errors"
"fmt"
"github.com/spf13/viper"
"go.uber.org/zap"
)
@ -15,7 +14,7 @@ var (
}
)
func Init(logger *zap.Logger) {
func Init(logger *zap.Logger) error {
viper.SetConfigName("config")
viper.SetConfigType("yaml")
@ -29,10 +28,11 @@ func Init(logger *zap.Logger) {
err := viper.ReadInConfig()
if err != nil {
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 {
logger.Fatal("Fatal error config file", zap.Error(err))
logger.Info("Config file not found, using default settings.")
return nil
}
return err
}
return nil
}