如何将go mod升级到v2或更高版本?

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.

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 submodule, 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;

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.