Showing Some Love To Go Packages

Last month, I wanted to figure out the nicest way to make my Go package import URL look nice and short. First thing was to change the go.mod file and set the name.

But then I had to figure out how to make go get respect that, so that it actually works.The way importing from arbitrary URLs works is that go get will try fetching the URL and look for meta tags in the HTML page at that address. If you check the HTML source behind any repository’s page on GitHub, you’ll find go-import meta tag in it.

This is well-known and documented behavior. But as you can see, it still refers to the namespaced URL (and rightfully so).

I searched for the best way to enable a web server on my domain to serve such tags. Between running one of the micro tools that do just that, using GitHub Pages or simple web hosting, none of the options seemed streamline enough.

Being slightly obsessed with making things neat (my wife teaches me to be neat almost every day — and I’ll never reach her level!), I thought “wouldn’t it be cool to have a small service that handles this and just this thing nicely?”

But alas, there was no such a service that I can find.

This meant I either forget about it and do something that kind of works, or I spend my weekend hacking away! As if working on my main project during the weekdays wasn’t enough. But there was no stopping…

It needed it to be so simple I can launch it within a day or so. So I decided to forego much of the complexity associated with setting up package prefix mapping in the UI (it’s such a rabbit hole) and figured there’s a much easier way to do this: DNS records! So, if you own a domain and want to use it for your packages, you can simply use TXT records to store it:

(This is what I see in my DNS zone editor)

This way, it’s easy to establish the exact configuration and mapping that needs to get rendered for go get —making it (and me) happy.

Late Saturday, the proof of concept worked! But I couldn’t leave it at that. I needed the entire weekend to be spent hunched over keyboard.

This is how Gopkg was born. I decided that the utility of it is sufficient to share it with others. So I took the rest of the weekend (and some more) to make it presentable and at least somewhat useful to other. I even commissioned a cute logo with Go’s mascot!

Also, it turned out that using DNS records is a great way to establish authenticity of HTML meta tags are being generated by the service: simply look up the TXT records and see if they match, since these records are under original author’s control and not Gopkg’s.

Now that it’s out and in public beta (what do these words mean nowadays, anyway?) I can go back to more work. I’ll be updating Gopkg to make it better and even more useful in the coming weeks (there’s going to be some feature creep!)

Do you have a Go package and you want its import URL look better? Do you want to get some package use statistics? Get a nicely looking site and multi-version documentation hosted at package’s URL? Then go check Gopkg out and maybe you’ll be as happy as I am!

Tech entrepreneur, open source developer. Amateur cyclist.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store