Go modules in gihub repos

91 views
Skip to first unread message

Victor Denisov

unread,
Nov 19, 2020, 9:58:05 PM11/19/20
to golang-nuts
Hi,

I've recently encountered an interesting behavior of go modules.
I have a library in a repository on github. The go.mod file for this library is not in the root directory of the repo. I create a signed tag in the repo, say v1.2.3.
However when I try referring the full path to the module in the go.mod of my application that uses this library I can't do it because go build complains that ref v1.2.3 is not found.

The line that I specify in my go.mod looks as follows:

However when I don't specify anything in the go.mod of my application, go build successfully finds the module however it uses absolute version reference in go.mod

Can someone comment on this topic? I'm trying to understand whether it's ok to have go.mod not in the root directory. Is this behavior intentional or just a coincidence.

Thanks in advance,
Victor.

Dan Kortschak

unread,
Nov 19, 2020, 10:08:09 PM11/19/20
to golan...@googlegroups.com
You should tag the version with the path to the module root: for
example path/from/root/v1.2.3
> --
> 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/65736f44-901b-435a-990f-7f6ee9dde588n%40googlegroups.com
> .


Victor Denisov

unread,
Nov 19, 2020, 10:29:16 PM11/19/20
to Dan Kortschak, golan...@googlegroups.com
Interesting. Thanks, I'll give it a try.

You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/7Z6U5aKxaJI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/3c1c0d314bc2bd519a06035d940ae4c8ba5ab8c1.camel%40kortschak.io.

Dan Kortschak

unread,
Nov 19, 2020, 10:39:24 PM11/19/20
to golan...@googlegroups.com
Reference: https://golang.org/ref/mod#vcs-version

> If a module is defined in a subdirectory within the repository, that
> is, the module subdirectory portion of the module path is not empty,
> then each tag name must be prefixed with the module subdirectory,
> followed by a slash. For example, the module golang.org/x/tools/gopls
> is defined in the gopls subdirectory of the repository with root path
> golang.org/x/tools. The version v0.4.0 of that module must have the
> tag named gopls/v0.4.0 in that repository.
Reply all
Reply to author
Forward
0 new messages