99 "reflect"
1010 "strings"
1111
12- "github.com/go-playground/validator "
13- "github.com/mcuadros/ go-defaults "
12+ "github.com/creasty/defaults "
13+ "github.com/go-playground/validator/v10 "
1414 "github.com/spf13/pflag"
1515 "github.com/spf13/viper"
1616 "gopkg.in/yaml.v3"
@@ -96,7 +96,7 @@ func (l *Loader) Load(config interface{}) error {
9696 }
9797
9898 // Apply default values before reading configuration
99- defaults .SetDefaults (config )
99+ defaults .Set (config )
100100
101101 // Bind flags dynamically using reflection on `cmdx` tags if a flag set is provided
102102 if l .flags != nil {
@@ -116,11 +116,11 @@ func (l *Loader) Load(config interface{}) error {
116116 }
117117 }
118118
119- // Attempt to read the configuration file
119+ // Attempt to read the configuration file (missing file is not an error).
120120 if err := l .v .ReadInConfig (); err != nil {
121121 var configFileNotFoundError viper.ConfigFileNotFoundError
122- if errors .As (err , & configFileNotFoundError ) {
123- fmt .Println ( "Warning: Config file not found. Falling back to defaults and environment variables." )
122+ if ! errors .As (err , & configFileNotFoundError ) && ! os . IsNotExist ( err ) {
123+ return fmt .Errorf ( "failed to read config file: %w" , err )
124124 }
125125 }
126126
@@ -139,7 +139,7 @@ func (l *Loader) Load(config interface{}) error {
139139
140140// Init initializes the configuration file with default values.
141141func (l * Loader ) Init (config interface {}) error {
142- defaults .SetDefaults (config )
142+ defaults .Set (config )
143143
144144 path := l .v .ConfigFileUsed ()
145145 if fileExists (path ) {
0 commit comments