As mentioned here one can get all the standard Go packages using https://godoc.org/golang.org/x/tools/go/packages 's Load() function in which one can give "pattern" as input.
pkgs, err := packages.Load(nil, pattern)
For example, if pattern = "std" then it returns all the standard packages.
But, if I want to get a list of custom/user-defined packages having custom patterns such as only the vendor folders of the form github.com/X/Y/vendor/... then how exactly I can specify the pattern?
I have tried using /vendor/, github.com/X/Y/vendor/ and some other combinations as pattern in the Load() function. None of them have worked.
You can use the
...syntax inpatternfield of theLoad()function.Example
My Go module requires
github.com/hashicorp/go-multierrorpackage :So, the following code :
returns all the required packages starting with
github.com/hashicorp(even transitive ones) :Note that you can also use
...anywhere in your pattern (...hashicorp...,...ha...corp...,github.com/...).