go get can't work with a non-routeable IP address

527 Views Asked by At

I have a git repo setup on a computer on my local network (192.168.0.12). It has an entry in /etc/hosts

192.168.0.12    ubuntu-18-extssd

go get doesn't recognize my hostname (ubuntu-18-extssd) as a host name so I use the IP address instead.

Now when I try with go get like this

go get 192.168.0.12/gitrepo/go-package-test-stringutil/stringpackage

it returns the error

package 192.168.0.12/gitrepo/go-package-test-stringutil/stringpackage: unrecognized import path "192.168.0.12/gitrepo/go-package-test-stringutil/stringpackage": https fetch: Get "https://192.168.0.12/gitrepo/go-package-test-stringutil/stringpackage?go-get=1": dial tcp 192.168.0.12:443: connect: connection refused

So I tell git to use ssh instead:

git config --global url."[email protected]:".insteadOf "https://192.168.0.12/"

and in my ~/.gitconfig I have

[url "[email protected]:"]
    insteadOf = https://github.com/
[url "[email protected]:"]
    insteadOf = https://192.168.0.12/

But go get still gives the same error. The entry for github works, though.

Why is the combination of go get and git still trying to use https when I've told it to use ssh instead?

1

There are 1 best solutions below

0
On

Go cannot infer the repository type from 192.168.0.12/gitrepo/go-package-test-stringutil/stringpackage directly, so it's trying to lookup the meta tags at https://192.168.0.12/gitrepo/go-package-test-stringutil/stringpackage?go-get=1:

If the import path is not a known code hosting site and also lacks a version control qualifier, the go tool attempts to fetch the import over https/http and looks for a tag in the document's HTML .

https://golang.org/cmd/go/#hdr-Remote_import_paths

If you don't want to run a server that returns the appropriate meta tags you have to let Go know that the package is in a git repository by adding .git to the import path. Use one of the following commands, depending on where your repository is located:

go get 192.168.0.12/gitrepo/go-package-test-stringutil/stringpackage.git
go get 192.168.0.12/gitrepo/go-package-test-stringutil.git/stringpackage
go get 192.168.0.12/gitrepo.git/go-package-test-stringutil/stringpackage