Implements the wildcard file matching in Go used by golint, go test etc.
import "github.com/mgechev/dots"
func main() {
result, err := dots.Resolve([]string{"./fixtures/..."}, []string{"./fixtures/foo"})
for _, f := range result {
fmt.Println(f);
}
}
If we suppose that we have the following directory structure:
βββ README.md
βββ fixtures
βΒ Β βββ bar
βΒ Β βΒ Β βββ bar1.go
βΒ Β βΒ Β βββ bar2.go
βΒ Β βββ baz
βΒ Β βΒ Β βββ baz1.go
βΒ Β βΒ Β βββ baz2.go
βΒ Β βΒ Β βββ baz3.go
βΒ Β βββ foo
βΒ Β βββ foo1.go
βΒ Β βββ foo2.go
βΒ Β βββ foo3.go
βββ main.go
The result will be:
fixtures/bar/bar1.go
fixtures/bar/bar2.go
fixtures/baz/baz1.go
fixtures/baz/baz2.go
fixtures/baz/baz3.go
dots
supports wildcard in both - the first and the last argument of Resolve
, which means that you can ignore files based on a wildcard:
dots.Resolve([]string{"github.com/mgechev/dots"}, []string{"./..."}) // empty list
dots.Resolve([]string{"./fixtures/bar/..."}, []string{"./fixture/foo/...", "./fixtures/baz/..."}) // bar1.go, bar2.go
dots
allow you to receive a slice of slices where each nested slice represents an individual package:
dots.ResolvePackages([]string{"github.com/mgechev/dots/..."}, []string{})
So we will get the result:
[
[
"$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/bar/bar1.go",
"$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/bar/bar2.go"
],
[
"$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/baz/baz1.go",
"$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/baz/baz2.go",
"$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/baz/baz3.go"
],
[
"$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/foo/foo1.go",
"$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/foo/foo2.go",
"$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/foo/foo3.go"
],
[
"$GOROOT/src/github.com/mgechev/dots/fixtures/pkg/baz/baz1.go",
"$GOROOT/src/github.com/mgechev/dots/fixtures/pkg/baz/baz2.go"
],
[
"$GOROOT/src/github.com/mgechev/dots/fixtures/pkg/foo/foo1.go",
"$GOROOT/src/github.com/mgechev/dots/fixtures/pkg/foo/foo2.go"
],
[
"$GOROOT/src/github.com/mgechev/dots/fixtures/pkg/foo/bar/bar1.go"
]
]
This method is especially useful, when you want to perform type checking over given package from the result.
MIT