David Fregoli
Projects Blog

Go vanity imports with Caddy in 10 lines

March 13, 2026 · 1 min read

If you want go get yourdomain.com/pkg to work, you need your domain to serve a <meta name="go-import"> tag. The typical approach involves setting up a dedicated service or creating static HTML files per package.

With Caddy, you can do it dynamically for all packages with a single config block:

yourdomain.com {
    @goget query go-get=1
    handle @goget {
        respond `<!DOCTYPE html><html><head><meta name="go-import" content="yourdomain.com{path} git https://github.com/yourusername{path}"></head></html>` 200
    }

    handle {
        redir https://github.com/yourusername{uri} temporary
    }
}

That's it. Any path under your domain automatically maps to the corresponding GitHub repo. go get yourdomain.com/foo resolves to github.com/yourusername/foo. Browser visits redirect to GitHub.

I was previously doing this with GitHub Pages, which required creating a directory and index.html for each package. This Caddy approach handles everything dynamically — add a new repo on GitHub and the vanity import works immediately.

The {path} placeholder is the key. Caddy substitutes the request path directly into the meta tag, so /mister becomes yourdomain.com/mister git https://github.com/yourusername/mister. The @goget matcher ensures the meta tag is only served to the Go toolchain (which sends ?go-get=1), while normal browser requests get a redirect.