Naming is a very important thing, but everyone is different.

Why is replace used

In the beginning, I wrote A project A with A repository named project-alpha, but the package in go.mod is set to When I want to reference the code of project A in another project B, generally speaking, Using, because go get will use git, but due to the warehouse is not the same as the name of the package and code, need to use the replace conversion:

Package require v0.0.0 replace v1.0.0Copy the code

Use go mod Edit to set replace:

Go mod edit - the replace[email protected]Copy the code

Note: this command only sets replace; require requires another setting, and the dependency version of require is ignored; replace’s dependency version is used.

Other use scenarios for Replace

Fix dependency that cannot be downloaded

Go mod edit-replace[email protected]Copy the code

Note: The target version must conform to the SemVer specification, not master and latest (go get can be used).

The resources

  • Go get the source code
  • Use replace in go modules
  • Semantic Versioning