Problems encountered when migrating to modules #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
If you opted into Go Modules, you must comply with the specification of "Releasing Modules for v2 or higher" available in the Modules documentation and enforced since the most recent versions of Go. Quoting the specification:
Issue 1: The module path declaration is wrong
The latest version of
CrunchyData/postgres-operator
is v4.3.2, it’s a v2+ module. So, you need to declare the module path like this:(This is for the commit with the version tag v4.x.y)
Or, the downstream modules users cannot require your package normally, they will get an error like:
** Solution **:
You can see the import statements within the module here:
https://github.com/CrunchyData/postgres-operator/search?q=github.com%2Fcrunchydata%2Fpostgres-operator&unscoped_q=github.com%2Fcrunchydata%2Fpostgres-operator
Issue 2: github.com/evanphx/json-patch stuck in the older version
Before you opted into Go Modules, the version of
evanphx/json-patch
is v4.6.0.https://github.com/CrunchyData/postgres-operator/blob/master/Gopkg.toml#L16
After you opted into Go Modules, the version of
evanphx/json-patch
turn to v4.2.0.postgres-operator/go.mod
Line 7 in 682bf03
If you didn't do it on purpose, then I think the root cause of this issue is:
evanphx/json-patch
opted into Go Modules.evanphx/json-patch
didn’t comply with the specification of "Releasing Modules for v2 or higher".github.com/evanphx/json-patch/go.mod
(It should be “module github.com/evanphx/json-patch/v4”)
** Solution **:
Since it's against one of the design choices of Go, it'll be a bit of a hack. Instead of go get github.com/evanphx/json-patch@version-tag, the install procedure would be something like:
(1)Search for the tag you want (in browser)
(2)Get the commit hash for the tag you want
(3)Run go get github.com/evanphx/json-patch@commit-hash
(4)Edit the go.mod file to put a comment about which version you actually used
For example:
If you want to get the github.com/evanphx/json-patch v4.6.0(Latest commit bf22ed9 on 21 Dec 2019), you need to edit the go.mod file like this:
This way seems good, but if the users try to use
go get -u
, they will get the old version and break again. So be cautious here.References