Solved thanks to Daniel Martí; use `go list -json` and grab the Module
struct out of that.

On Tue, 2019-12-24 at 09:50 +1030, Dan Kortschak wrote:
> Say I have a package path, "host.org/user/depmodule/pkgdep", which is
> the path to a dependency of "host.org/user/repomain/pkgmain". The
> go.mod file in host.org/user/repomain will have a line
> "host.org/user/depmodule" in the require block. If I want to
> programmatically find what the module path is from the package path
> "host.org/user/depmodule/pkgdep", how can I do this?
> 
> go list -m only works with module paths, so doing `go list -m
> host.org/user/depmodule/pkgdep' when I'm in 
> host.org/user/repomain/pkgmain gives me:
> 
> go list -m: module host.org/user/depmodule/pkgdep: not a known
> dependency
> 
> Is there a way I can use go list to get this information, or a helper
> function somewhere that does this? (The go tool must have this
> capacity
> since go get depends on it when grabbing dependencies).
> 
> thanks
> Dan
> 

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20bc47818c468b0ba43f6957c4e6a2a96b22dda1.camel%40kortschak.io.

Reply via email to