github.com/docker/app@v0.9.1-beta3.0.20210611140623-a48f773ab002/internal/yaml/yaml.go (about) 1 package yaml 2 3 import ( 4 "bytes" 5 "io" 6 7 "gopkg.in/yaml.v2" 8 ) 9 10 // Unmarshal decodes the first document found within the in byte slice 11 // and assigns decoded values into the out value. 12 // 13 // See gopkg.in/yaml.v2 documentation 14 func Unmarshal(in []byte, out interface{}) error { 15 d := yaml.NewDecoder(bytes.NewBuffer(in)) 16 err := d.Decode(out) 17 if err == io.EOF { 18 return nil 19 } 20 return err 21 } 22 23 // Marshal serializes the value provided into a YAML document. The structure 24 // of the generated document will reflect the structure of the value itself. 25 // Maps and pointers (to struct, string, int, etc) are accepted as the in value. 26 // 27 // See gopkg.in/yaml.v2 documentation 28 func Marshal(in interface{}) ([]byte, error) { 29 return yaml.Marshal(in) 30 } 31 32 // NewDecoder returns a new decoder that reads from r. 33 // 34 // See gopkg.in/yaml.v2 documentation 35 func NewDecoder(r io.Reader) *yaml.Decoder { 36 return yaml.NewDecoder(r) 37 }