path/filepath: Change example to print the correct path on failure

This commit is contained in:
Erwin Oegema 2018-03-26 15:18:04 +02:00 committed by GitHub
parent d2dd2e1524
commit 398c1eeb61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -80,13 +80,14 @@ func ExampleJoin() {
// a/b/c // a/b/c
// a/b/c // a/b/c
} }
func ExampleWalk() { func ExampleWalk() {
dir := "dir/to/walk" dir := "dir/to/walk"
subDirToSkip := "skip" // dir/to/walk/skip subDirToSkip := "skip" // dir/to/walk/skip
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
fmt.Printf("prevent panic by handling failure accessing a path %q: %v\n", dir, err) fmt.Printf("prevent panic by handling failure accessing a path %q: %v\n", path, err)
return err return err
} }
if info.IsDir() && info.Name() == subDirToSkip { if info.IsDir() && info.Name() == subDirToSkip {