Use local repository as the dependencies in golang

In my development, I extract some common feature to a dependent project, and in the main project use the mod to include it, but when I need…

Use local repository as the dependencies in golang

In my development, I extract some common feature to a dependent project, and in the main project use the mod to include it, but when I need to update the common functions, I need to commit the common codes to the repository and get them to the main project, so I want to use the local repository as the dependencies, so I don’t need to upload the code to remote before I tested in the main project.

I find the solution from the link below:

Using “replace” in go.mod to point to your local module

Solution

The solution from the article above is use the replace to specify the local dir of the common project, the example go module file is like below.

module github.com/pselle/foo 
 
replace github.com/pselle/bar => /Users/pselle/Projects/bar 
 
require ( 
 github.com/pselle/bar v1.0.0 
)