Convert a go.mod file into checked out dependencies

120 views
Skip to first unread message

Kevin Burke

unread,
Jan 12, 2022, 1:58:30 PM1/12/22
to golang-nuts
Hi,
Sometimes I just want to inspect third party code for a library, and/or edit it. 

I'm looking for a tool that will read all of the dependencies in a go.mod file and then check out all of the right versions of all of the source code into the right places in a $GOPATH. Does that exist? 

Failing that, is there a tool that will read a go.mod file and give me version information about each dependency? I see packages.Load, but that doesn't seem super targeted for the use case; if it's the best that exists then I'll probably make it work.

Kevin


Robert Dionne

unread,
Jan 12, 2022, 3:28:49 PM1/12/22
to Kevin Burke, golang-nuts

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/18fca322-5913-4cc8-bbd3-fc84f4f0e673n%40googlegroups.com.

Kevin Burke

unread,
Jan 12, 2022, 3:43:36 PM1/12/22
to golang-nuts
Ah, yes, that would work but wouldn't include the git history... 

Dan Kortschak

unread,
Jan 12, 2022, 3:58:08 PM1/12/22
to golan...@googlegroups.com
While not a tool, there is code that can be bent to this in
golang.org/x/pkgsite/internal/source. I used that to get repo
information for a tool to obtain homepage and issue page links from Go
executables[1]. You could easily extend that kind of approach to get
the actual repo at the relevant version.

[1]
https://github.com/kortschak/ugbt/blob/master/internal/modrepo/repo.go

Paul Jolly

unread,
Jan 15, 2022, 1:01:26 AM1/15/22
to Kevin Burke, golang-nuts
Hi Kevin,

As I replied on Gophers Slack:

go list -m all will give you information about dependencies. Add -json
to give you that in a more easily parsed format.

https://github.com/rogpeppe/gohack can be used to do what you want
with respect to checking out from VCS using the -vcs flag in
combination with the GOHACK env var appropriate set for the module in
question.


Paul
Reply all
Reply to author
Forward
0 new messages