Esempio n. 1
0
func Register() {
	configr.RegisterFileDecoder(Name, configr.FileDecoderAdapter(json.Unmarshal), "json", "JSON")

	jsonEncoder := func(v interface{}) ([]byte, error) {
		return json.MarshalIndent(v, "", "	")
	}
	configr.RegisterFileEncoder(Name, configr.EncoderAdapter(jsonEncoder), "json", "JSON")
}
Esempio n. 2
0
func Register() {
	configr.RegisterFileDecoder(Name, configr.FileDecoderAdapter(toml.Unmarshal), "toml", "TOML")

	tomlEncoder := func(v interface{}) ([]byte, error) {
		var tomlBytes bytes.Buffer
		tomlEncoder := toml.NewEncoder(bufio.NewWriter(&tomlBytes))
		err := tomlEncoder.Encode(v)
		if err != nil {
			return tomlBytes.Bytes(), err
		}

		return tomlBytes.Bytes(), nil
	}
	configr.RegisterFileEncoder(Name, configr.EncoderAdapter(tomlEncoder), "toml", "TOML")
}