func initConfig() {
	if cfgFile != "" {
		// Use config file from the flag.
		viper.SetConfigFile(cfgFile)
	} else {
		// Find home directory.
		home, err := homedir.Dir()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		// Search config in home directory with name ".consulctl" (without extension).
		viper.AddConfigPath(home)
		viper.SetConfigName(".consulctl")
	}

	viper.AutomaticEnv() // read in environment variables that match

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


	// setup base url for API access

	// I acknowledge it can be difficult to add it as a hostname, so "consul-node" is the fallback if
	// no env-vars have been defined and the --consul-address is not set
	if consulAddress == "" {
		consulAddress = os.Getenv("CONSULE_NODE")
		if consulAddress == "" {
			consulAddress = "consul-node"
		}
	}

	if protocol == "" {
		protocol = "http"
	}

	if consulPort == "" {
		consulPort = "8500"
	}

	baseURL = protocol + "://" + consulAddress + ":" + consulPort + "/v1"
}
// initConfig reads in config file and ENV variables if set.
initConfig reads in config file and ENV variables if set.
// initConfig reads in config file and ENV variables if set .
func initConfig() {
	if cfgFile != "" {
		viper.SetConfigFile(cfgFile)
	} else {
		home, err := homedir.Dir()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		viper.AddConfigPath(home)
		viper.SetConfigName(".consulctl")
	}
	viper.AutomaticEnv() 
	if err := viper.ReadInConfig(); err == nil {
		fmt.Println("Using config file:", viper.ConfigFileUsed())
	}
	if consulAddress == "" {
		consulAddress = os.Getenv("CONSULE_NODE")
		if consulAddress == "" {
			consulAddress = "consul-node"
		}
	}
	if protocol == "" {
		protocol = "http"
	}
	if consulPort == "" {
		consulPort = "8500"
	}
	baseURL = protocol + "://" + consulAddress + ":" + consulPort + "/v1"
}
func initConfig ( ) { if cfgFile != " " { viper . SetConfigFile ( cfgFile ) } else { home , err := homedir . Dir ( ) if err != nil { fmt . Println ( err ) os . Exit ( 1 ) } viper . AddConfigPath ( home ) viper . SetConfigName ( " " ) } viper . AutomaticEnv ( ) if err := viper . ReadInConfig ( ) ; err == nil { fmt . Println ( " " , viper . ConfigFileUsed ( ) ) } if consulAddress == " " { consulAddress = os . Getenv ( " " ) if consulAddress == " " { consulAddress = " " } } if protocol == " " { protocol = " " } if consulPort == " " { consulPort = " " } baseURL = protocol + " " + consulAddress + " " + consulPort + " " }
initConfig reads in config file and ENV variables if set.
initConfig reads in config file and ENV variables if set .
// Use config file from the flag. // Find home directory. // Search config in home directory with name ".consulctl" (without extension). // read in environment variables that match // If a config file is found, read it in. // setup base url for API access // I acknowledge it can be difficult to add it as a hostname, so "consul-node" is the fallback if // no env-vars have been defined and the --consul-address is not set