1

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."dean@192.168.0.12:".insteadOf "https://192.168.0.12/"

and in my ~/.gitconfig I have

[url "git@github.com:"]
    insteadOf = https://github.com/
[url "dean@192.168.0.12:"]
    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?

Dean Schulze
  • 9,633
  • 24
  • 100
  • 165
  • Host names are part of the import path, not the package name. I've also tried with the hostname and it fails with the same message. Here is the git origin: `$ git remote --v origin dean@ubuntu-18-extssd:gitrepo/go-package-test-stringutil (fetch)` – Dean Schulze Sep 07 '20 at 22:46
  • Sorry, I meant import path. The mechanism for locating repositories Is documented at https://golang.org/cmd/go/#hdr-Remote_import_paths – JimB Sep 07 '20 at 23:40
  • Those are all public URLs. The problem I've run into is that `go get` doesn't know what to do with a git repo on a private, on-prem, non-routable IP. `go get` has a proxy setup that does some magic with those well-known public IPs. Apparently it fails with a non-routable IP. – Dean Schulze Sep 08 '20 at 01:48
  • Is port 443 open on 192.168.0.12? Sounds like port 22 or 21 (SSH) is open but not 443. Do you have a web server running on 192.168.0.12? The IP address 192.168.0.12 is most definitely routable, just not routable across the internet. What happens if you open a browser and go to `https://192.168.0.12`? The error states that the connection has been refused. – Matt Oestreich Sep 08 '20 at 06:28
  • No web server running on my host. I use ssh for git access. The .gitconfig entry should be converting the https: request to ssh. I've also tried ssh://dean@192.168.0.12: but get the same result. – Dean Schulze Sep 08 '20 at 14:11
  • Here's my [detailed answer](https://stackoverflow.com/questions/60645866/how-can-i-make-go-get-work-with-a-repo-on-a-local-server/65209006#65209006). It covers, packages, modules, and `go get`. – Dean Schulze Dec 09 '20 at 02:46
  • Here's my [detailed answer](https://stackoverflow.com/questions/60645866/how-can-i-make-go-get-work-with-a-repo-on-a-local-server/65209006#65209006) covering packages, modules, and `go get`. – Dean Schulze Dec 09 '20 at 02:48
  • Here's my [detailed answer](https://stackoverflow.com/questions/60645866/how-can-i-make-go-get-work-with-a-repo-on-a-local-server/65209006#65209006) covering packages, modules, and `go get`. – Dean Schulze Dec 09 '20 at 02:51

1 Answers1

1

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
Peter
  • 29,454
  • 5
  • 48
  • 60