Skip to content

Commit

Permalink
Refactor grab function code
Browse files Browse the repository at this point in the history
Remove unnecessary check for document node type nodes.

Refactor code to be more compact.
  • Loading branch information
HeavyWombat committed Sep 4, 2020
1 parent 3f1e5d6 commit ccfad22
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions getting.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@ func Grab(node *yamlv3.Node, pathString string) (*yamlv3.Node, error) {
return nil, err
}

if node.Kind == yamlv3.DocumentNode {
if len(node.Content) != 1 {
panic("unsure of implementation detail document node with multiple nodes")
}
switch node.Kind {
case yamlv3.DocumentNode:
return grabByPath(node.Content[0], path)

entry := node.Content[0]
return grabByPath(entry, path)
default:
return grabByPath(node, path)
}

return grabByPath(node, path)
}

func grabByPath(node *yamlv3.Node, path Path) (*yamlv3.Node, error) {
Expand Down

0 comments on commit ccfad22

Please sign in to comment.