Exemplo n.º 1
0
// GetPlaceHolders uses the provided viper configuration to extract properties that have placeholders in is values
func GetPlaceHolders(conf *viper.Viper) Placeholders {
	list := parseMap(conf.AllSettings())

	properties := CreateProperties(list)

	return Placeholders{properties}
}
Exemplo n.º 2
0
func getFileExtension(v *viper.Viper) string {
	filename := v.ConfigFileUsed()
	extension := filepath.Ext(filename)

	extension = strings.Replace(extension, ".", "", 1)

	return extension
}
Exemplo n.º 3
0
func readConfigFile(v *viper.Viper) string {

	filename := v.ConfigFileUsed()

	r, err := fileReader(filename)

	if err != nil {
		return ""
	}

	configFile, err := ioutil.ReadAll(r)

	if err != nil {
		return ""
	}

	return string(configFile)
}
Exemplo n.º 4
0
func render(v *viper.Viper, configOutputType string) ([]byte, error) {

	var b []byte
	var err error
	var conf = make(map[string]interface{})

	m := v.AllSettings()

	b, err = yaml.Marshal(m)

	err = yaml.Unmarshal(b, conf)

	if err == nil {
		switch configOutputType {
		case "json":

			b, err = json.MarshalIndent(conf, "", "    ")

		case "toml":
			var buff bytes.Buffer

			err = toml.NewEncoder(&buff).Encode(conf)
			b = buff.Bytes()

		case "yaml", "yml":

			b, err = yaml.Marshal(conf)

		}
	}

	if err != nil {
		return nil, err
	}

	return b, nil

}