Exports visit function from base.
This commit is contained in:
parent
b07f916cbb
commit
b59d136820
|
@ -254,14 +254,14 @@ func float64ToUintValueFunc() mapstructure.DecodeHookFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// visitFn is a callback that gets a chance to visit each file found during a
|
// VisitFn is a callback that gets a chance to visit each file found during a
|
||||||
// traversal with visit().
|
// traversal with visit().
|
||||||
type visitFn func(path string) error
|
type VisitFn func(path string) error
|
||||||
|
|
||||||
// visit will call the visitor function on the path if it's a file, or for each
|
// visit will call the visitor function on the path if it's a file, or for each
|
||||||
// file in the path if it's a directory. Directories will not be recursed into,
|
// file in the path if it's a directory. Directories will not be recursed into,
|
||||||
// and files in the directory will be visited in alphabetical order.
|
// and files in the directory will be visited in alphabetical order.
|
||||||
func visit(path string, visitor visitFn) error {
|
func Visit(path string, visitor VisitFn) error {
|
||||||
f, err := os.Open(path)
|
f, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error reading %q: %v", path, err)
|
return fmt.Errorf("error reading %q: %v", path, err)
|
||||||
|
|
|
@ -108,10 +108,10 @@ func TestConfigUtil_Visit(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
basePath := "../../test/command/merge"
|
basePath := "../../test/command/merge"
|
||||||
if err := visit(basePath, visitor); err != nil {
|
if err := Visit(basePath, visitor); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
if err := visit(path.Join(basePath, "subdir", "c.json"), visitor); err != nil {
|
if err := Visit(path.Join(basePath, "subdir", "c.json"), visitor); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue