fix: use logger and return errors
This commit is contained in:
parent
a54341dd68
commit
b8572ea712
|
@ -2,7 +2,6 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
@ -15,7 +14,7 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init(logger *zap.Logger) {
|
func Init(logger *zap.Logger) error {
|
||||||
viper.SetConfigName("config")
|
viper.SetConfigName("config")
|
||||||
viper.SetConfigType("yaml")
|
viper.SetConfigType("yaml")
|
||||||
|
|
||||||
|
@ -29,10 +28,11 @@ func Init(logger *zap.Logger) {
|
||||||
err := viper.ReadInConfig()
|
err := viper.ReadInConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.As(err, &viper.ConfigFileNotFoundError{}) {
|
if errors.As(err, &viper.ConfigFileNotFoundError{}) {
|
||||||
// Config file not found, this is not an error.
|
logger.Info("Config file not found, using default settings.")
|
||||||
fmt.Println("Config file not found, using default settings.")
|
return nil
|
||||||
} else {
|
|
||||||
logger.Fatal("Fatal error config file", zap.Error(err))
|
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue