Golang private modules conf: meta tags, git+ssh, nginx
From wikinotes
This configuration abstracts golang module path,
to provide access to private go modules over git+ssh,
by setting dynamic html meta tags using nginx.
WARNING:
This works on the machine I created the package on (from outside of package), but doesn't seem to work on other computers
Setup
Workstation
Add Private URL
First, add the target URL to your
$GOPRIVATE
environment variable using one of the following methods:# ~/.config/go/env GOPRIVATE="example.com/x/*"Create Repo
// main.go package main import "fmt" func main() { fmt.Println("hello") }// go.mod module example.com/x/hello go 1.18git commit -m 'init' git pushWebServer
# /usr/local/etc/nginx/nginx.conf http { location / { root /usr/local/www/example.com; index index.html; } location ~ ^/x/(?<go_project>[^/]+)$ { root /usr/local/www/example.com; rewrite ^ /gopkg.html; sub_filter '{TARGET_PROJECT}' '$go_project' sub_filter_once off; } }<!-- /usr/local/www/example.com/gopkg.html --> <html> <head> <meta name="go-import" content="example.com/x/{TARGET_PROJECT} git git+ssh://foo:/repos/{TARGET_PROJECT}"> </head> </html>Package Consumers
# ~/.ssh/config Host foo Hostname example.com IdentityFile ~/.ssh/user User usergo install example.com/x/hello
Troubleshooting
# is 'example/x/*' in your GOPRIVATE envvar? go env | grep -e GOPRIVATE -e 'example/x' # can you clone the project over ssh normally? git clone foo:/repos/hello # does the package/path look correct in your meta-tag? curl https://example.com/x/foo # debug logging go install -v example/x/foo@latest # debug logging for go, git+ssh GIT_SSH_COMMAND='ssh -vvv' \ go install -v example/x/foo@latest