go-walker is a library that supports walking a directory structure, including local and remote file system. This library includes the iterator
, modeutil
, oserror
, pathutil
, and walker
packages. The walker
package is the main package and the rest are supporting packages.
Go
You can import go-walker as a library with:
import (
"github.com/spatialcurrent/go-walker/pkg/walker"
)
The easiest pattern is to create a walker that can be reused multiple times.
w, err := walker.NewWalker(&walker.NewWalkerInput{
SkipPath: nil,
SkipFile: nil,
SkipLink: nil,
ErrorLinkStat: nil,
ErrorStat: nil,
ErrorWalk: nil,
Limit: walker.NoLimit,
})
You can call the Walk
method of the walker multiple times, and in concurrent goroutines. The Walk
method requires a root context, slice of root directories, and a walk function. The context enables easier use of the walker across multiple API boundaries. The context
is not used by the walker itself, but is simply passed through to the walk function.
n, err := w.Walk(context.Background(), []string{"testdata"}, func(ctx context.Context, p string, f File) error {
// retrieve value from context if you like
// do something with each file
return nil
})
See walker in GoDoc for API documentation.
To run Go tests use make test_go
(or bash scripts/test.sh
), which runs unit tests, go vet
, go vet with shadow
, errcheck, ineffassign, staticcheck, and misspell.
Spatial Current, Inc. is currently accepting pull requests for this repository. We'd love to have your contributions! Please see Contributing.md for how to get started.
This work is distributed under the MIT License. See LICENSE file.