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:
committed by
Darren Shepherd
parent
79b91ea33c
commit
59c4a298e8
25
types/encoder.go
Normal file
25
types/encoder.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user