go get <meta> tag
This note descibes how Golang figures out where to clone a dependency from.
How it works
Go documents the functionality here: Remote import paths .
This is the short version:
go get git.domain.com/foo/bar, go does the following:
- Check if that page contains a meta tag like this (could also be a https url):
<meta name="go-import" content="git.domain.com git firstname.lastname@example.org:foo/bar.git">
- Verify that
git.domain.comcontains the same meta tag
- Git clone
If you’re using packages hosted on an internal git instance (e.g. GitLab), you are going to be in trouble.
GitLab for example shows the https url in the meta-tag, so
go get will prompt for authentication.
The best solution would be to be able to configure GitLab to show the ssh url instead of https. Until then, here are a few approaches, choose the one that fit’s your flow.
Customize it in the
In my opinion this is the best solution:
[url "email@example.com:"] insteadOf = "https://git.domain.com"
Drawback: You have to configure this on every host.
Build your own discovery service
You could add your own service on some domain (e.g.
go.domain.com or even
add it to your company website) which contains the correct meta tag with the ssh
Drawback: You have an additional service which can break.
Use `.git` in your import paths
If you run
go get git.domain.com/foo/bar.git and import it this way, i
it will fetch the git URL without checking the tag.
Drawback: You have to remember adding
.git and it’s not really common.