예제 #1
0
func GenerateConfig(token string) {
	if _, err := os.Stat(fullFileLocation()); err == nil {
		logger.Debug("Config file already exists")
	} else {
		logger.Debug("Generating new config file at " + fullFileLocation() + "...")
		content := []byte("[authentication]\ntoken = \"" + token + "\"\n")
		err := ioutil.WriteFile(fullFileLocation(), content, 0644)
		if err != nil {
			logger.Info("There was a problem writing your config file")
		}
	}
}
예제 #2
0
// Read in config file and ENV variables if set.
func ConfigInit() {
	viper.SetConfigType(fileType)
	if ConfigFile != "" { // enable ability to specify config file via flag
		viper.SetConfigFile(ConfigFile)
	}

	viper.SetConfigName(fileName) // name of config file (without extension)
	viper.AddConfigPath(filePath) // adding home directory as first search path
	viper.AutomaticEnv()          // read in environment variables that match

	// If a config file is found, read it in.
	if err := viper.ReadInConfig(); err == nil {
		logger.Debug("Using config file: " + viper.ConfigFileUsed())
	}
}