Skip to content

Commit

Permalink
add GetPaths method for node (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 23, 2023
1 parent c263f29 commit a582d96
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions internal/object/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@ type Node struct {
Children []*Node
}

func (n *Node) GetPaths() []string {
if len(n.Children) == 0 {
return []string{n.Name}
}

var paths []string
for _, child := range n.Children {
ps := child.getPaths(n.Name)
paths = append(paths, ps...)
}

return paths
}

func (n *Node) getPaths(parentDir string) []string {
if len(n.Children) == 0 {
return []string{fmt.Sprintf("%s/%s", parentDir, n.Name)}
}

var paths []string
for _, child := range n.Children {
ps := child.getPaths(fmt.Sprintf("%s/%s", parentDir, n.Name))
paths = append(paths, ps...)
}

return paths
}

type Tree struct {
object *Object
Children []*Node
Expand Down

0 comments on commit a582d96

Please sign in to comment.