Setup private Go modules
You have a git repositiory on a remote server. This is probably a VPS you have online at Digital Ocean, AWS, or some other hosting company. Could also be a docker container or raspberrypi under your desk.
Regardless, you can include the repositiory in your go projects by helping git (which Go uses) to know how to access the code over SSH.
~/.gitconfig and make sure your host is listed. Below are examples for github, bitbucket, and my own custom VPS.
[url "firstname.lastname@example.org:"] insteadOf = https://github.com/ [url "email@example.com:"] insteadOf = https://bitbucket.org/ [url "firstname.lastname@example.org:"] insteadOf = https://xeoncross.com/
Then you can checkout the repo as a go module. Note, you have to use the
go get -v -x xeoncross.com/repos/golib.git
Next you need to setup Module configuration for non-public modules (disable proxy sum checking)
go env -w GOPRIVATE=xeoncross.com
Now you can use the module in your import paths:
Related issues and discussions:
If you are writing multiple sibling modules at the same time it could be beneficial to use relative paths in your modules so you don't have to commit changes and update the dependent module for each change.
In this case, you can use the replace directive.
replace also can be used to inform the go tooling of the relative or absolute on-disk location of modules in a multi-module project, such as:
replace example.com/project/foo => ../foo
Instead of editing your
go.mod file directly use the
go mod command:
go mod edit -replace xeoncross.com/repos/golib.git=/Users/owner/path/here
You can read more here: https://thewebivore.com/using-replace-in-go-mod-to-point-to-your-local-module/