What are vanity import paths — screenshot of sagikazarmark.hu

What are vanity import paths

This post details my experience migrating a Go library to a vanity import path. Vanity imports provide a stable, controlled path for your packages, signaling project maturity and decoupling your code from specific hosting providers.

Visit sagikazarmark.hu →

Questions & Answers

What are vanity import paths in Go?
Vanity import paths in Go are custom URLs that redirect the go get command to a specific version control repository, such as GitHub. They enable developers to use a stable, branded import path for their packages, independent of the underlying hosting service.
Who should use vanity import paths for their Go projects?
Vanity import paths are for Go project maintainers and organizations who want to establish a stable and professional identity for their packages. They are particularly beneficial for serious projects that aim to convey longevity and control over their code's distribution.
How do vanity import paths differ from standard Go import paths?
Standard Go import paths typically directly reference a hosting provider (e.g., github.com/user/repo). Vanity import paths, however, use a custom domain (e.g., myproject.dev/package) and rely on HTML meta tags on a web server to redirect the go get tool to the actual repository. This provides greater control and portability.
When is it recommended to implement vanity import paths for a Go module?
It is recommended to implement vanity import paths when a Go module is intended to be a serious, long-term project. They should be used when the author desires a stable, brandable import path that can persist even if the underlying code host changes.
How does the go command resolve a vanity import path?
When go get encounters a vanity import path (e.g., emperror.dev/errors), it sends an HTTP request to that URL with a ?go-get=1 query parameter. The web server at that URL must respond with HTML containing a <meta name="go-import" content="import-prefix vcs repo-root"> tag, which directs the go tool to the actual repository location.