// newViper generates a viper configuration object which
// merges (in order from highest to lowest priority) the
// command line options, configuration file options, and
// default configuration values. This viper object becomes
// the single source of truth for the app configuration.
newViper generates a viper configuration object which
merges (in order from highest to lowest priority) the
command line options, configuration file options, and
default configuration values. This viper object becomes
the single source of truth for the app configuration.
// newViper generates a viper configuration object which // merges ( in order from highest to lowest priority ) the // command line options configuration file options and // default configuration values . This viper object becomes // the single source of truth for the app configuration .
func newViper(appName, cfgFile string) *viper.Viper {
	log := logrus.New()
	v := viper.New()
	v.SetEnvPrefix(appName)
	v.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
	v.AutomaticEnv()
	v.SetConfigName(fmt.Sprintf("config-%s", appName))
	v.AddConfigPath(".")
	if cfgFile != "" {
		v.SetConfigFile(cfgFile)
	}
	v.SetConfigType("json")
	if err := v.ReadInConfig(); err == nil {
		log.WithField("file", v.ConfigFileUsed()).Infof("config file loaded")
		v.WatchConfig()
		v.OnConfigChange(func(e fsnotify.Event) {
			log.WithField("file", e.Name).Info("config file changed")
		})
	} else {
		if cfgFile != "" {
			log.WithError(err).Warningf("Error reading config file: %v", cfgFile)
		}
	}
	if log.Level == logrus.DebugLevel {
		v.Debug()
	}
	return v
}
func newViper ( appName , cfgFile string ) * viper . Viper { log := logrus . New ( ) v := viper . New ( ) v . SetEnvPrefix ( appName ) v . SetEnvKeyReplacer ( strings . NewReplacer ( " " , " " ) ) v . AutomaticEnv ( ) v . SetConfigName ( fmt . Sprintf ( " " , appName ) ) v . AddConfigPath ( " " ) if cfgFile != " " { v . SetConfigFile ( cfgFile ) } v . SetConfigType ( " " ) if err := v . ReadInConfig ( ) ; err == nil { log . WithField ( " " , v . ConfigFileUsed ( ) ) . Infof ( " " ) v . WatchConfig ( ) v . OnConfigChange ( func ( e fsnotify . Event ) { log . WithField ( " " , e . Name ) . Info ( " " ) } ) } else { if cfgFile != " " { log . WithError ( err ) . Warningf ( " " , cfgFile ) } } if log . Level == logrus . DebugLevel { v . Debug ( ) } return v }
newViper generates a viper configuration object which
merges (in order from highest to lowest priority) the
command line options, configuration file options, and
default configuration values.
newViper generates a viper configuration object which merges ( in order from highest to lowest priority ) the command line options configuration file options and default configuration values .