コード例 #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}
}
コード例 #2
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

}