Created
April 15, 2020 11:54
-
-
Save yanniszark/c6f347421a1eeb75057ff421e03fd57c to your computer and use it in GitHub Desktop.
Golang: Multiple YAML Documents / Split YAML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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