0

I have a (private) github repo with a Go module. I've added the tag v0.1 and github shows that tag. I have set go env -w GOPRIVATE=github.com/dwschulze/key-value-mod and my ~/.gitconfig has [url "git@github.com:"] insteadOf = https://github.com/

But go get can't retrieve my module:

$ go get github.com/dwschulze/key-value-mod
go: github.com/dwschulze/key-value-mod upgrade => v0.0.0-20210907155619-9116b97467d6
go get: github.com/dwschulze/key-value-mod@v0.0.0-20210907155619-9116b97467d6: parsing go.mod:
        module declares its path as: key-value-mod
                but was required as: github.com/dwschulze/key-value-mod

$ go get github.com/dwschulze/key-value-mod@v0.1
go get github.com/dwschulze/key-value-mod@v0.1: no matching versions for query "v0.1"

What problem is go get having?

Dean Schulze
  • 9,633
  • 24
  • 100
  • 165
  • `go get github.com/dwschulze/key-value-mod@latest` does this work – whitespace Sep 07 '21 at 16:50
  • @whitespace - No. It gives `go: github.com/dwschulze/key-value-mod latest => v0.0.0-20210907155619-9116b97467d6`. Same as above. – Dean Schulze Sep 07 '21 at 17:07
  • 2
    are you sure you published your `git tag`? You can tag a release locally - but it may not be pushed to the remote repo. Does the tag release appear on the github web portal? If not: `git push --tags` – colm.anseo Sep 07 '21 at 17:33
  • Yes the tag is published. I also published another tag 0.1 just in case there was a problem with the 'v', but it does the same thing. I think `go get` is just broken. – Dean Schulze Sep 07 '21 at 18:17

3 Answers3

2

Based on the error, I don't think you have any issues with the private repo. Rather, it seems to me that your go.mod file declares the module as

module key-value-mod

...

while it should be

module github.com/dwschulze/key-value-mod

...
  • 1
    Yes, it seems to be an unstated requirement that the module name has to be the repo url: https://groups.google.com/g/golang-nuts/c/hLkhogyFLWI. The other thing that helped was to clear the mod cache. – Dean Schulze Sep 07 '21 at 20:09
2

Two things were causing this. I had to clear my module cache. The second is as Simon mentions above the module name has to be the repo URL where the module will be published.

I don't like the close coupling that go modules have with source code repositories, but that is reality.

Dean Schulze
  • 9,633
  • 24
  • 100
  • 165
  • 1
    On top of that, the `semver` format is still required. While you can `go get @v0.1` (without a patch number), the remote git tag *MUST* have the 3-number (`vMajor.Minor.Patch`) format to work. – colm.anseo Sep 07 '21 at 20:55
1

Your go modules semver of v0.1 is incorrect for go modules consumption. It includes a major version, minor version - but is missing the patch number:

v1.4.0-beta.2

Note: the Pre-release Identifier suffix here (-beta.2) is optional.

See also publishing go modules docs:

Every required module in a go.mod has a semantic version, the minimum version of that dependency to use to build the module.

A semantic version has the form vMAJOR.MINOR.PATCH.

So update your tag to v0.1.0 and it should work.

colm.anseo
  • 19,337
  • 4
  • 43
  • 52