1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-18 08:14:56 +00:00

add yaml support

This commit is contained in:
Daishan Peng
2018-05-24 10:28:05 -07:00
committed by Darren Shepherd
parent 79b91ea33c
commit 59c4a298e8
7 changed files with 80 additions and 20 deletions

25
types/encoder.go Normal file
View File

@@ -0,0 +1,25 @@
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
}