Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-files
Commits
e1ba4f66
Commit
e1ba4f66
authored
Aug 15, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
walk: add a walk function
parent
f3569282
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
+27
-0
walk.go
walk.go
+27
-0
No files found.
walk.go
0 → 100644
View file @
e1ba4f66
package
files
import
(
"path/filepath"
)
// Walk walks a file tree, like `os.Walk`.
func
Walk
(
nd
Node
,
cb
func
(
fpath
string
,
nd
Node
)
error
)
error
{
var
helper
func
(
string
,
Node
)
error
helper
=
func
(
path
string
,
nd
Node
)
error
{
if
err
:=
cb
(
path
,
nd
);
err
!=
nil
{
return
err
}
dir
,
ok
:=
nd
.
(
Directory
)
if
!
ok
{
return
nil
}
iter
:=
dir
.
Entries
()
for
iter
.
Next
()
{
if
err
:=
helper
(
filepath
.
Join
(
path
,
iter
.
Name
()),
iter
.
Node
());
err
!=
nil
{
return
err
}
}
return
iter
.
Err
()
}
return
helper
(
""
,
nd
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment