Go Vanity URLs

Photo by Andrew Neel on Unsplash

Go Vanity URLs

How to have a custom Golang import domain.

Have you ever seen this type of import?

import (

Since I came from Java, I always thought Uber had a type of "Maven Central" for Golang.

But that is not the case. And it is cleaner.

What do I need?

One thing: a page with specifics <meta> tags pointing to the actual git repository.

Check this from Uber FX library:

❯ http https://go.uber.org/fx
HTTP/1.1 200 OK
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
        <meta name="go-import" content="go.uber.org/fx git https://github.com/uber-go/fx">
        <meta name="go-source" content="go.uber.org/fx https://github.com/uber-go/fx https://github.com/uber-go/fx/tree/master{/dir} https://github.com/uber-go/fx/tree/master{/dir}/{file}#L{line}">
        <meta http-equiv="refresh" content="0; url=https://pkg.go.dev/go.uber.org/fx">
        Nothing to see here. Please <a href="https://pkg.go.dev/go.uber.org/fx">move along</a>.

You see that the URL returns a index.html with 3 meta tags pointing to:

  • the git repository

  • the source code inside the repository

  • a redirect to the docs, if you try to access it through the browser


So you need to put an index.html page like that one inside your custom domain, and serve it. The go tool will check that page and redirect it to the actual repository.


Using website.org as a custom domain example, If I want the users to use an import like this:

import (

I need to create an index.html like below:

<!DOCTYPE html>
        <meta name="go-import" content="go.website.org/mylib git https://github.com/myusername/mylib">
        <meta name="go-source" content="go.website.org/mylib https://github.com/myusername/mylib https://github.com/myusername/mylib/tree/master{/dir} https://github.com/myusername/mylib/tree/master{/dir}/{file}#L{line}">
        <meta http-equiv="refresh" content="0; url=https://pkg.go.dev/go.website.org/mylib">

And put in a web server for that domain, where the URL


Serves the index.html above.

And make sure that your repository is publicly available. If not, only you will have access to it.

And more

You can make the root go.website.org as an index list to all your packages like Uber


To learn more

Check the reference on Golang Docs.