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.
Edit your ~/.gitconfig
and make sure your host is listed. Below are examples for github, bitbucket, and my own custom VPS.
[url "[email protected]:"]
insteadOf = https://github.com/
[url "[email protected]:"]
insteadOf = https://bitbucket.org/
[url "[email protected]:"]
insteadOf = https://xeoncross.com/
Then you can checkout the repo as a go module. Note, you have to use the .git
extension.
go get -v -x xeoncross.com/repos/lib
Next you need to setup Module configuration for non-public modules (disable proxy sum checking)
go env -w GOPRIVATE=xeoncross.com,github.com/privateorg
or whole paths on github
go env -w GOPRIVATE=github.com/usernamespace
Now you can use the module in your import paths:
import "xeoncross.com/repos/golib.git/a"
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/