Skip to content

Commit 46a80be

Browse files
Merge pull request GoogleCloudPlatform#1272 from justinsb/refactor_splityaml
Refactor: rewrite SplitYAML to be more conventional
2 parents 919e064 + 1177fcd commit 46a80be

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

operator/scripts/utils/yaml.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,16 @@ func SplitYAML(yamlBytes []byte) ([][]byte, error) {
6666
r := bytes.NewReader(yamlBytes)
6767
dec := goyaml.NewDecoder(r)
6868
results := make([][]byte, 0)
69-
var value map[string]interface{}
70-
for eof := dec.Decode(&value); errors.Is(eof, io.EOF); eof = dec.Decode(&value) {
71-
if eof != nil {
72-
return nil, eof
69+
for {
70+
var value map[string]interface{}
71+
err := dec.Decode(&value)
72+
if err != nil {
73+
if errors.Is(err, io.EOF) {
74+
break
75+
}
76+
return nil, fmt.Errorf("error decoding yaml: %w", err)
7377
}
78+
7479
bytes, err := goyaml.Marshal(value)
7580
if err != nil {
7681
return nil, fmt.Errorf("error marshalling '%v' to YAML: %w", value, err)

0 commit comments

Comments
 (0)