getvain

Vanity Import Paths for Golang Packages
Login

When a request includes go-get=1, the getvain service responds with a "go-import" <meta> tag, allowing go get to check code out of a version control system.

By default, getvain helps go get find packages via fossil, such that go get src.example.com/module/pkg finds a <meta> tag content "src.example.com/module/pkg fossil https://src.example.com/module".

The behavior can be modified with flags:

  -addr string
		listen on address, i.e. "localhost:8080"; if omitted, serve CGI
  -domain string
		domain where source code is found
  -strip uint
		strip text from start of path, i.e. -strip=1 to make /src/foo become repository foo
  -suffix string
		append suffix to repository name
  -v    verbose log
  -vcs string
		version control system (default "fossil")

Example: fossil via CGI

If fossil is configured to serve multiple repositories over CGI, you may find go get requests failing. Configuring fossil to serve a "go-import" meta tag can solve the problem, but may be difficult to configure for nested packages (i.e. go get src.example.com/module/pkgA/pkgB) Instead of configuring fossil to serve the <meta> tag, consider wrapping the fossil CGI script in a conditional script:

#!/bin/sh
# while not ideal to launch this script process with every request, we'd be launcing fossil anyway...
if [ "$QUERY_STRING" = "go-get=1" ]
then
    /bin/getvain
else
    /cgi-bin/fossil
fi

The result is that getvain serves requests from go-get, while fossil serves other requests.

CGI usage

When getvain is run as a CGI script, parameters can be placed in the cgi-bin file. For example, the equivalent of getvain -domain src.d10.dev -strip 0 -v becomes

#!/bin/getvain
-domain src.d10.dev
-strip 0
-v