Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to upgrade go mod to v2 or higher version?

Tags:

go

My go package version is v1.0.7 and now I want to upgrade it to v2.0.0. I create a new tag with it bug when I use go get CODEPATH it still use version v1.0.7. The go.mod should like require CODEPATH v2.0.0+incompatible but I want to know what command will do this?

The document Modules says that add /v2 to module path but didn't tell how to upgrade client's go.mod.

like image 876
Bryce Avatar asked Oct 17 '22 05:10

Bryce


2 Answers

I tried myself and it worked.

  1. Add /v2 to your go.mod's module line module github.com/mnhkahn/aaa/v2;
  2. If you import a sub-package of the module, import like this import "github.com/mnhkahn/aaa/v2/config";
  3. Create a tag with name v2.0.0;
  4. go get github.com/mnhkahn/aaa/v2;
  5. go mod tidy;
like image 151
Bryce Avatar answered Oct 21 '22 00:10

Bryce


The answer from Bryce looks good if you are doing this manually.

If you are interested in an automated approach (for example, perhaps you have many files you would need to visit), a good automated solution is https://github.com/marwan-at-work/mod, which can automatically add, remove, or change the required /vN in your *.go code and your go.mod. See this answer for more details.

like image 37
thepudds Avatar answered Oct 20 '22 22:10

thepudds