You can use golang.org/x/tools/go/packages
<https://godoc.org/golang.org/x/tools/go/packages> and call packages.Load.
It will accept both directory names and package names as the patterns.

Let us know if you need any more information!


On Tue, Nov 6, 2018 at 11:35 PM bsr <bsr...@gmail.com> wrote:

> How can I find the path (directory) of a package which uses go module
> (1.11).
>
> I had code (for  go:generate)  which uses package name to locate source
> code relative to GOPATH and import using
> https://golang.org/pkg/go/build/#Import
>
> Now, once I started using module, the package name is prefixed with module
> name and even if  I strip the module name, `build.Import` only look at
> GOROOT, and since no GOPATH is set, it won't search in the current package
> directory. using `os.Getwd` is not reliable as the source code is nested at
> different levels and can't reliably find the source.
>
> So, what is the best way to locate source (or the path ) based on package
> name of a go module enabled project.
>
> Any pointers greatly appreciated.
> thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to