func (c *Config) Load() error {

	configFiles := make([]string, 0, 3)

	if c.ConfigFile() == "" {
		log.Debug("User-specified config file not provided")
	} else {
		log.Debug("User-specified config file provided, will attempt to load it")
		configFiles = append(configFiles, c.ConfigFile())
	}

	localFile, err := c.localConfigFile()
	if err != nil {
		log.Error("Failed to determine path to local file")
	}
	configFiles = append(configFiles, localFile)

	userConfigFile, err := c.userConfigFile()
	if err != nil {
		log.Error("Failed to determine path to user config file")
	}
	configFiles = append(configFiles, userConfigFile)

	for _, file := range configFiles {
		log.Debugf("Trying to load config file %q", file)
		ok, err := c.loadConfigFile(file)
		if ok {
			c.configFileLoaded = true
			c.configFileUsed = file
			// if there were no errors, we're done loading config files
			log.WithFields(log.Fields{
				"config_file": file,
			}).Debug("Config file successfully loaded")
			log.Debug("Config file successfully parsed")
			log.Debugf("After loading config file: %v", c.String())
			break
		}

		log.Warnf("Config file %q not found or unable to load", file)
		log.WithFields(log.Fields{
			"error": err,
		}).Debug("")
	}

	if !c.configFileLoaded {
		return ErrCfgFileNotFound
	}

	return nil
}
// Load attempts to first load the user-specified config file, then falls back
// to checking for a config file in the directory alongside the executable,
// then finally a config file from the user's configuration path. An error is
// returned if the configuration file cannot be loaded.
Load attempts to first load the user-specified config file, then falls back
to checking for a config file in the directory alongside the executable,
then finally a config file from the user's configuration path. An error is
returned if the configuration file cannot be loaded.
// Load attempts to first load the user - specified config file then falls back // to checking for a config file in the directory alongside the executable // then finally a config file from the user ' s configuration path . An error is // returned if the configuration file cannot be loaded .
func (c *Config) Load() error {
	configFiles := make([]string, 0, 3)
	if c.ConfigFile() == "" {
		log.Debug("User-specified config file not provided")
	} else {
		log.Debug("User-specified config file provided, will attempt to load it")
		configFiles = append(configFiles, c.ConfigFile())
	}
	localFile, err := c.localConfigFile()
	if err != nil {
		log.Error("Failed to determine path to local file")
	}
	configFiles = append(configFiles, localFile)
	userConfigFile, err := c.userConfigFile()
	if err != nil {
		log.Error("Failed to determine path to user config file")
	}
	configFiles = append(configFiles, userConfigFile)
	for _, file := range configFiles {
		log.Debugf("Trying to load config file %q", file)
		ok, err := c.loadConfigFile(file)
		if ok {
			c.configFileLoaded = true
			c.configFileUsed = file
			log.WithFields(log.Fields{
				"config_file": file,
			}).Debug("Config file successfully loaded")
			log.Debug("Config file successfully parsed")
			log.Debugf("After loading config file: %v", c.String())
			break
		}
		log.Warnf("Config file %q not found or unable to load", file)
		log.WithFields(log.Fields{
			"error": err,
		}).Debug("")
	}
	if !c.configFileLoaded {
		return ErrCfgFileNotFound
	}
	return nil
}
func ( c * Config ) Load ( ) error { configFiles := make ( [ ] string , 0 , 3 ) if c . ConfigFile ( ) == " " { log . Debug ( " " ) } else { log . Debug ( " " ) configFiles = append ( configFiles , c . ConfigFile ( ) ) } localFile , err := c . localConfigFile ( ) if err != nil { log . Error ( " " ) } configFiles = append ( configFiles , localFile ) userConfigFile , err := c . userConfigFile ( ) if err != nil { log . Error ( " " ) } configFiles = append ( configFiles , userConfigFile ) for _ , file := range configFiles { log . Debugf ( " " , file ) ok , err := c . loadConfigFile ( file ) if ok { c . configFileLoaded = true c . configFileUsed = file log . WithFields ( log . Fields { " " : file , } ) . Debug ( " " ) log . Debug ( " " ) log . Debugf ( " " , c . String ( ) ) break } log . Warnf ( " " , file ) log . WithFields ( log . Fields { " " : err , } ) . Debug ( " " ) } if ! c . configFileLoaded { return ErrCfgFileNotFound } return nil }
Load attempts to first load the user-specified config file, then falls back
to checking for a config file in the directory alongside the executable,
then finally a config file from the user's configuration path.
Load attempts to first load the user - specified config file then falls back to checking for a config file in the directory alongside the executable then finally a config file from the user ' s configuration path .
// if there were no errors, we're done loading config files