getvain

Documentation
Login

Documentation

getvain is a simple HTTP server that supports vanity import paths for "go gettable" packages and modules.

Implementation

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

By default, getvain helps go get find packages via fossil. Specifically, go get src.example.com/module/pkg will receive a <meta> tag:

"src.example.com/module/pkg fossil https://src.example.com/module"

The default 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
-exec string
      program to execute when go-get is not present; honors GETVAIN_EXEC environment variable
-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

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

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 launching 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.

An alternative to the script above is to the -exec flag or set the GETVAIN_EXEC environment variable to the name of a command to execute when the query string does not contain "go-get=1". That is, instead of launching the script above, have CGI run getvain with GETVAIN_EXEC=/cgi-bin/fossil.