Background
At my company, we use Bit Bucket to host our git repos. All traffic to the server flows through a custom, non-standard port. Cloning from our repos looks something like git clone ssh://[email protected]:9999/repo/path/name.git
.
The problem
I would like to create Go modules hosted on this server and managed by go mod
, however, the fact that traffic has to flow through port 9999
makes this very difficult. This is because go mod
operates on the standard ports and doesn't seem to provide a way to customise ports for different modules.
My question
Is it possible to use go mod
to manage Go modules hosted on a private git server with a non-standard port?
Attempted solutions
Vendoring
This seems to be the closest to offering a solution. First I go mod vendor
the Go application that wants to use these Go modules, then I git submodule
the Go module in the vendor/
directory. This works perfectly up to the point that a module needs to be updated or added. go mod tidy
will keep failing to download or update the other Go modules because it cannot access the "git URL" of the custom Go module. Even when the -e
flag is set.
Editing .gitconfig
Editing the .gitconfig
to replace the URL without the port with the URL with the port is a solution that will work but is a very dirty hack. Firstly, these edits will have to be done for any new modules, and for every individual developer. Secondly, this might brake other git processes when working on these repositories.
The
go
tool uses git under the hood, so you'd want to configure git in your environment to use an alternate url. Something likeThough I recall that bitbucket/stash sometimes provides an extra suffix for reasons I don't recall, so you might need to do something like this:
ADDITIONAL EDIT
user bcmills mentioned below that you can also serve the go-import metadata over HTTPS, and use whatever vanity URL you like, provided you control the domain resolution. This can be done with varying degrees of sophistication, from a simple nginx rule to static content generators, dedicated vanity services or even running your own module proxy with Athens
This still doesn't completely solve the problem of build environment configuration, however, since you'll want the user to set
GOPRIVATE
orGOPROXY
or both, depending on your configuration.Also, if your chosen domain is potentially globally resolvable, you might want to consider registering it anyway to keep it from being registered by a potentially-malicious third party.