Skip to content

Instantly share code, notes, and snippets.

@yanniszark
Created April 15, 2020 11:54
Show Gist options
  • Save yanniszark/c6f347421a1eeb75057ff421e03fd57c to your computer and use it in GitHub Desktop.
Save yanniszark/c6f347421a1eeb75057ff421e03fd57c to your computer and use it in GitHub Desktop.
Golang: Multiple YAML Documents / Split YAML
import goyaml "github.com/go-yaml/yaml"
func SplitYAML(resources []byte) ([][]byte, error) {
dec := goyaml.NewDecoder(bytes.NewReader(resources))
var res [][]byte
for {
var value interface{}
err := dec.Decode(&value)
if err == io.EOF {
break
}
if err != nil {
return nil, err
}
valueBytes, err := goyaml.Marshal(value)
if err != nil {
return nil, err
}
res = append(res, valueBytes)
}
return res, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment