Go get-able CGit with Nginx

I always wanted my local git repo to be go-get-able. After some research, here is a simple solution.

First, enable clone-url option in your CGit config:

clone-url=https://$HTTP_HOST$SCRIPT_NAME/$CGIT_REPO_URL

Second, add following block to you nginx config. It serves proper meta-tag with actual repo location on go get requests, if go-get=1 query parameter is provided:

if ($arg_go-get = 1) {
    return 200 '<meta name="go-import" content="$host$uri git $scheme://$host/cgi-bin/cgit.cgi$uri.git">\n';
}

Similar setup works well with GitLab too.

See also:

By Dimitri Sokolyuk
Related articles