ginuerzh / gost

GO Simple Tunnel - a simple tunnel written in golang
MIT License
15.98k stars 2.48k forks source link

Cannot get latest version: module contains a go.mod file, so module path should be github.com/ginuerzh/gost/v2 #581

Open KateGo520 opened 4 years ago

KateGo520 commented 4 years ago

Background

The github.com/ginuerzh/gost uses Go modules and the current release version is v2. And it’s module path is "github.com/ginuerzh/gost", instead of "github.com/ginuerzh/gost/v2". It must comply with the specification of "Releasing Modules for v2 or higher" available in the Modules documentation. Quoting the specification:

A package that has opted in to modules must include the major version in the import path to import any v2+ modules To preserve import compatibility, the go command requires that modules with major version v2 or later use a module path with that major version as the final element. For example, version v2.0.0 of example.com/m must instead use module path example.com/m/v2. https://github.com/golang/go/wiki/Modules#releasing-modules-v2-or-higher

Steps to Reproduce

GO111MODULE=on, run go get targeting any version >= v2.7.0 of the ginuerzh/gost:

$ go get github.com/ginuerzh/gost@v2.11.0
go: finding github.com/ginuerzh/gost v2.11.0
go: finding github.com/ginuerzh/gost v2.11.0
go get github.com/ginuerzh/gost@v2.11.0: github.com/ginuerzh/gost@v2.11.0: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2

run go get github.com/ginuerzh/gost, the version will stuck in v2.6.1:

$go get github.com/ginuerzh/gost
go: downloading github.com/ginuerzh/gost v2.6.1+incompatible
go: github.com/ginuerzh/gost upgrade => v2.6.1+incompatible 

SO anyone using Go modules will not be able to easily use any newer version of ginuerzh/gost.

Solution

1. Kill the go.mod files, rolling back to GOPATH.

This would push them back to not being managed by Go modules (instead of incorrectly using Go modules). Ensure compatibility for downstream module-aware projects and module-unaware projects projects

2. Fix module path to strictly follow SIV rules.

Patch the go.mod file to declare the module path as github.com/ginuerzh/gost/v2 as per the specs. And adjust all internal imports. The downstream projects might be negatively affected in their building if they are module-unaware (Go versions older than 1.9.7 and 1.10.3; Or use third-party dependency management tools, such as: Dep, glide,govendor…).

*[]** You can see who will be affected here: [4 module-unaware users, i.e., andyYaoR/gost, whatedcgveg/gost, f4nff/ssh-pings] https://github.com/search?p=1&q=%22github.com%2Fginuerzh%2Fgost%22+filename%3AGodeps.json+filename%3Avendor.conf+filename%3Avendor.json+filename%3Aglide.toml+filename%3AGodep.toml&type=Code

If you don't want to break the above repos. This method can provides better backwards-compatibility. Release a v2 or higher module through the major subdirectory strategy: Create a new v2 subdirectory (github.com/ginuerzh/gost/v2) and place a new go.mod file in that subdirectory. The module path must end with /v2. Copy or move the code into the v2 subdirectory. Update import statements within the module to also use /v2 (import "github.com/ginuerzh/gost/v2/…"). Tag the release with v2.x.y.

3. Suggest your downstream module users use hash instead of a version tag.

If the standard rule of go modules conflicts with your development mode. Or not intended to be used as a library and does not make any guarantees about the API. So you can’t comply with the specification of "Releasing Modules for v2 or higher" available in the Modules documentation. Regardless, 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/ginuerzh/gost@version-tag, module users need to use this following way to get the ginuerzh/gost: (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/ginuerzh/gost@commit-hash (4) Edit the go.mod file to put a comment about which version you actually used This will make it difficult for module users to get and upgrade ginuerzh/gost.

*[]** You can see who will be affected here: [6 module users, e.g., maskedeken/gost-plugin, makazeu/libgost, dan-v/awslambdaproxy] https://github.com/search?q=github.com%2FLyricTian%2Fgin-admin+extension%3Amod&type=Code&ref=advsearch&l=&l=

Summary

You can make a choice to fix DM issues by balancing your own development schedules/mode against the affects on the downstream projects.

For this issue, Solution 2 can maximize your benefits and with minimal impacts to your downstream projects the ecosystem.

References

KateGo520 commented 4 years ago

@ginuerzh @bnuhero

ginuerzh commented 4 years ago

There is a plan (maybe a long term) to migrate the project to https://github.com/go-gost. The structure of the entire code will be refactored significantly, and the version will be bumped to v3.

KateGo520 commented 4 years ago

@ginuerzh Thank you for your reply and look forward to the new version