Skip to content

Commit

Permalink
Refactor: rewrite SplitYAML to be more conventional
Browse files Browse the repository at this point in the history
I think the behaviour here changes in the lint-fixes; refactor to
follow the normal pattern so this is more self-evident code.
  • Loading branch information
justinsb committed Feb 21, 2024
1 parent f7113d8 commit 1177fcd
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions operator/scripts/utils/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,16 @@ func SplitYAML(yamlBytes []byte) ([][]byte, error) {
r := bytes.NewReader(yamlBytes)
dec := goyaml.NewDecoder(r)
results := make([][]byte, 0)
var value map[string]interface{}
for eof := dec.Decode(&value); errors.Is(eof, io.EOF); eof = dec.Decode(&value) {
if eof != nil {
return nil, eof
for {
var value map[string]interface{}
err := dec.Decode(&value)
if err != nil {
if errors.Is(err, io.EOF) {
break
}
return nil, fmt.Errorf("error decoding yaml: %w", err)
}

bytes, err := goyaml.Marshal(value)
if err != nil {
return nil, fmt.Errorf("error marshalling '%v' to YAML: %w", value, err)
Expand Down

0 comments on commit 1177fcd

Please sign in to comment.