1
0
mirror of https://github.com/rancher/norman.git synced 2025-07-12 14:49:53 +00:00
norman/types/encoder.go
2018-06-04 16:44:48 -07:00

26 lines
411 B
Go

package types
import (
"encoding/json"
"io"
"github.com/ghodss/yaml"
)
func JSONEncoder(writer io.Writer, v interface{}) error {
return json.NewEncoder(writer).Encode(v)
}
func YAMLEncoder(writer io.Writer, v interface{}) error {
data, err := json.Marshal(v)
if err != nil {
return err
}
buf, err := yaml.JSONToYAML(data)
if err != nil {
return err
}
_, err = writer.Write(buf)
return err
}