Including privately hosted go module

I’m new to golang and inherited a codebase that I am trying to run. In the source code I’m executing go build ., but that complains aboouot missing go.sum entry, and helpfully it tells me what to do: go mod download Now the problem is that private-host is a bitbucket server running on default port 7990 and using port number in module name/require is not allowed. Next attempt to download source code and put it under $GOPATH/src/ directory, but that doesn’t help, go is still trying to download from private bitbucket server and failing because there is no way to include port number. How can I use that module (it is auto-generated from swagger.yaml file) in my other source code? It seems like the issue might because there is a tag(?) added after module name in go.mod file ( v0.0.0-20220613162241-f7f8a7118946), but I have no idea where is it coming from and how can I edit it to match what is in $GOPATH/src/ path…

Hi @Rapolas_K,

You could try telling Git (that Go uses under the hood unless you use another VCS) to use ssh instead of HTTP by adding an url insteadOf to your Git config:

[url "ssh://"]
	insteadOf =

(To be honest, I never tried that option on a private Git server.)

If the ssh fallback does not work, try pre-downloading the code into $GOPATH/pkg/mod/ (The go command does not search the $GOPATH/src path for cached modules AFAIK.)

As a last resort, you could install a Go proxy server, but this is the most involved option.

The funny tag is an auto-generated version number. Go adds this when the module has no tagged version number. This should not cause any issue with the download, but you would want to add the correct version to go.mod (like v1.2.3).

Thanks for your reply. Changing git config works for git, but Go doesn’t seem to care about it. Tried both http (replacing with http with port number) and ssh versions.

Cloning repo into $GOPATH/pkg/mod/ also didn’t help. Any attempt to use harbor-client immediately makes Go attempt to download and complain about “unrecognized import path dial connect: connection refused”, that makes sense, as the server is not listening on port 80 (nor 443).

I’ll see if I can figure out how to setup Go proxy server.

You might also try setting up a simple HTTP server that maps an import path to a VCS URL, as described here: Go Modules Reference > Version control systems

TL;DR: (shortened and with added emphasizes)

If the module path has a VCS qualifier (one of .bzr, .fossil, .git, .hg, .svn) at the end of a path component, the go command will [use the respective VCS to download the repo]

If the module path does not have a qualifier, the go command sends an HTTP GET request to a URL derived from the module path with a ?go-get=1 query string. For example, for the module, the go command may send the following requests: (preferred)  (fallback, only with GOINSECURE)

The go command follows redirects but otherwise ignores response status codes, so the server may respond with a 404 or any other error status. The GOINSECURE environment variable may be set to allow fallback and redirects to unencrypted HTTP for specific modules.

The server must respond with an HTML document containing a <meta> tag in the document’s <head>. The <meta> tag should appear early in the document to avoid confusing the go command’s restricted parser. In particular, it should appear before any raw JavaScript or CSS. The <meta> tag must have the form:

<meta name="go-import" content="root-path vcs repo-url">

[For example:]

<meta name="go-import" content=" git">

From this response, the go command will use the Git repository at the remote URL


After the repository URL is found, the go command will clone the repository into the module cache.

In your case, if you are able to host the HTTP server directly at on port 80 or 443, the meta tag to be returned would look like this:

<meta name="go-import" content=" git">

Thanks again. Unfortunately, I can’t spin a proxy server on the same host where bitbucket is running, so trying to run it on different server. Renaming module to use and re-runing go build gives similar output as before:

go: downloading v0.0.0-20220613162241-f7f8a7118946
labeller.go:11:2: invalid version: git ls-remote -q origin in $GOPATH/pkg/mod/cache/vcs/b71575aafda93a8fbd9cd241334506eb4dfca3833bf87653e766ff3bcb0ab801: exit status 128:
        fatal: remote error: Repository not found
        The requested repository does not exist, or you do not have permission to
        access it.

Even if manually executing git ls-remote -q origin in $GOPATH/pkg/mod/cache/vcs/b71575aafda93a8fbd9cd241334506eb4dfca3833bf87653e766ff3bcb0ab801 gives no output and exit status of 0.

If I change module to have .git at the end, it complains about missing go.sum entry:

labeller.go:11:2: missing go.sum entry; to add it:
        go mod download

Executing go mod download gives another error:

go: verifying go.mod: reading 404 Not Found
        server response:
        not found: invalid version: git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/vcs/48c1bdabe3cdfb3202eaeb030dd0ca5f558a9b11751613f733f01661d5814cab: exit status 128:
                fatal: transport 'git' not allowed

Note, cloning with git via proxy server using http works fine.

Apologies, for some reasons, I did not receive a notification about your previous update.

I realize I did not ask whether you have set the GOPRIVATE env variable to include the module import URL. This should suppress queries to the sun database that resulted in the 404 error. (see Go Modules Reference - The Go Programming Language)

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.