go get
sure is neat, huh? Want some code, and know that it's hosted on Github? just go get github.com/USER/REPO
and you're good to go! But what if you're a go-getter (heh) and want some vanity in your life?
How about this?
$ go get jameshunt.us/bolo/core
It's incredibly easy to do. You'll need the following:
- An SSL/TLS certificate (check out these guys)
- The ability to modify the raw HTML of your website
- Some nginx-fu (other web servers are do-able, but won't be covered here)
Set Your Meta
Let's say you want to be able to do this:
$ go get example.com/extras/fun
yet pull the code from the example/extras-fun
repo on Gihub?
All you need to do is add the following <meta> tag, with the correct name
and content
attributes, to the page at http://example.com/extras/fun
:
<meta name="go-import"
content="example.com/extras/fun git https://github.com/example/extras-fun">
That's it.
The content of the meta tag (the metadata itself), is three space-separated tokens:
- import prefix ("example.com/extras/fun")
- vcs ("git")
- repository ("https://github.com/example/extras-fun"
The import prefix is the top-level of the module being imported. More on that lter.
The vcs is a short string identifying which version control system needs to be used to pull down the repository code. Valid values are "git", and some others that I don't use.
The repository is the full URL to the repository to retrieve. In other words, our Github repository URL (in read-only mode).
What About Submodules?
If you have submodules (say extra/fun/times
) that need to be go-gettable in their own right, you do the same thing. I mean, you add the exact same meta tag to the page for times
:
<meta name="go-import"
content="example.com/extras/fun git https://github.com/example/extras-fun">
You have to do the first step though. Why? Given:
$ go get example.com/extras/fun/times
go get
will do the following:
- Retrieve
https://example.com/extras/fun/times
- Look for the
go-import
<meta> tag - Check that the import prefix matches "example.com/extras/fun/times"
- Seeing that it does not:
- Retrieve
https://example.com/extras/fun
- Look for the
go-import
<meta> tag - Check that the import prefix matches "example.com/extras/fun"
- Clone the $vcs repository at $repository
- Retrieve
Note that step 4.c does its matching based on the previous import prefix (as determined in step 3)
Wait, Why SSL?
At the outset, I mentioned needing an SSL/TLS certificate. Technically speaking, you don't need it, but if you don't encrypt your endpoint, go-getters will need the ugly -insecure
flag. It's best just to avoid it, given that you can get a single-domain certificate for about $5/year from here.