fix: include v2 in go module path #303
Merged
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.
Ookay so, I failed to consider that in Go, versions after
v1
need to have the version included in their module path.The Go Team suggests achieving this by copying all the
v2
code into av2
subdirectory. I dislike this approach because the most recent version of the module isn't in the repo root. In our case, it would be extra confusing because this repo is also used for Swagger and Js client. That means we would havev2/go
, so the most up-to-datego
directory would be hidden and the rest of the files in the root would still be aboutv2
of Swagger and Js. Orrr we could put those underv2
as well, but no one from the JS world is going to expect that.The Go Team recommends this because the module path is going to match the file structure, so imports without Go modules are still going to work. However, as Go progresses fewer people are using old versions that don't use go modules so will be less of a problem.
The other suggested option is to create a
v2
branch. However, we don't really need ourv1
code to exist alongside ourv2
code - it's very unlikely that we're going to make a fix tov1
, we're almost certainly just going to apply it tov2
an expect that users will use that version. And, we're still going to have the problem of making it look good with the Swagger and Js side.So, I'm taking the third option which is just to append
v2
to the end of the module path. If works well and keeps the branching and directory structure clean. Thoughts welcome from others with strong opinions about Go modules, I just formed mine today 😁The official Go explanation of this situation is hard to scan, I recommend https://donatstudios.com/Go-v2-Modules