Wildcard Pattern
The go
tool has a number of commands to help you with your code development. For example, the go list
command helps you list Go files in your current directory, and the go test
command helps you run test files in your current directory.
Your project may be structured in multiple subdirectories to help organize your code logically. If you wanted to use the go
tool to run commands over your whole codebase at once, it supports a wildcard pattern that helps you do just that.
To list all the .go
files in your current directory and its subdirectories, you can use the following relative pattern:
go list ./...
Similarly, if you wanted to run all the tests in your current directory and subdirectories, the same pattern can be used:
go test ./...
If you are still using vendor directories, the good thing is that this pattern will ignore the ./vendor
directories.
Let's try the wildcard patterns on the Go workshop repository.
To list all the .go
files...