This question already has an answer here:
I host my git repositories on a personal VPS and I have one package that I want to make "go get"-able. I have tried to set everything up per the help document found by issuing "go help importpath" with no luck. No matter what I do I get the following error:
package example.com/user/package: unrecognized import path "example.com/user/package"
I've tried every combination of the mentioned META tag with the same results.
<meta name="go-import" content="example.com git http://example.com/user/package">
The actual git repository is accessible via http://example.com/user/package.git. I am able to clone it directly but I want go to download and install it properly.
Per the help document, if go makes a request to http://example.com/user/package?go-get=1 the page returned contains the META tag. If go then makes a subsequent request to http://example.com/?go-get=1 the page returned also contains the exact same META tag.
Does any special configuration need to be done on the server? I wouldn't think so since go would be accessing the repository via an http request.
I'm at my wits end. Any help you can provide would be greatly appreciated.
</div>
This is the meta tag I've configured nginx to return for a gitlab server: if you request http://mygit.server/group/project?go-get=1
you get:
<meta content='mygit.server/group/project git git+ssh://git@mygit.server/group/project.git' name='go-import'>
And it works like a charm.
Here is the nginx rewrite rule that does this:
location ~ "(/[^/]+/[^/]+)(/.*)?" {
if ($arg_go-get = "1") {
echo '<html><head><meta name="go-import" content="my.domain.com$1 git git+ssh://git@my.domain.com$1"/></head></html>';
}
try_files $uri $uri/index.html $uri.html @gitlab;
}
This of course assumes you're working with git over ssh. If you're using https rewrite the url accordingly.
I've just done this for myself - similar scenario: a few small go repos and a mostly-private website. Nginx configuration:
root /var/www;
location / {
try_files $uri?$args $uri $uri/ @my-proxy;
}
I then run:
$ echo '<html><head><meta name="go-import" content="example.com/project-name git git+ssh://example.com/~/code/magic/blah/project-name.git" /></head></html>' > /var/www/project-name\?go-get\=1
<meta />
tagThe cost is an extra stat() call per hit to the location block, but you avoid the dreaded nginx if
directive and the out-of-tree echo
module, and can trivially tweak the meta content per-repository.
If those weird filenames bug you, you could restrict the scope: import "example.com/code/project-name"
in your .go files, andlocation /code { try_files ... }
in nginx.
Just to expand on @Not_a_Golfer answer, which was very helpful.
I have that for my Gerrit installation using Gitiles for browsing source code, so now godoc works (It links documentation to the right line of code):
# http://stackoverflow.com/questions/26347516/using-go-get-on-a-personal-git-repo/26348986#26348986
location ~ "(/[^/]+)(/.*)?" {
if ($arg_go-get = "1") {
echo '<html><head><meta name="go-import" content="myserver.example.com$1 git https://myserver.example.com$1"/><meta name="go-source" content="myserver.example.com$1 https://myserver.example.com/plugins/gitiles$1 https://myserver.example.com/plugins/gitiles$1/+/master/{dir} https://myserver.example.com/plugins/gitiles$1/+/master/{dir}/{file}#{line}" /></head></html>';
}
try_files $uri @gerrit;
}
location / {
try_files $uri @gerrit;
}