Skip to content

Add Go proxy tag to go-get response

Problem to solve

As a user, I want to easily fetch Go modules from GitLab's Go proxy, so I can develop with less friction. Currently, using GitLab's Go proxy requires a lot of configuration.

Intended users

User experience goal

The user should be able to fetch Go modules from GitLab's Go proxy with zero configuration.

Proposal

Modify Gitlab::Middleware::Go to include <meta name="go-import" content="gitlab.com/my/go/lib mod https://gitlab.com/api/v4/projects/123/packages/go" /> in the response to https://gitlab.com/my/go/lib?go-get=1, assuming that my/go/lib is Project(id: 123) on GitLab.com:

 <html>
 
 <head>
     <meta name="go-import" content="gitlab.com/my/go/lib git https://gitlab.com/my/go/lib.git">
+    <meta name="go-import" content="gitlab.com/my/go/lib mod https://gitlab.com/api/v4/projects/123/packages/go">
     <meta name="go-source" content="gitlab.com/my/go/lib https://gitlab.com/my/go/lib https://gitlab.com/my/go/lib/-/tree/master{/dir} https://gitlab.com/my/go/lib/-/blob/master{/dir}/{file}#L{line}">
 </head>
 
 <body>
     <pre>go get https://gitlab.com/my/go/lib</pre>
 </body>
 
 </html>

Further details

Go is weird

Permissions and Security

Omit the new tag for unauthorized requests. Omit the tag if Feature.enabled?(:go_proxy, project) is not true.

Documentation

  • doc/user/packages/go_proxy/index.md should be updated

What does success look like, and how can we measure that?

go get -x -v gitlab.com/my/go/lib uses GitLab's Go proxy without any manual configuration (such as modifying GOPROXY).