Go dependencies
Site admins can sync Go modules from any from any Go module proxy, including open source code from proxy.golang.org or a private proxy such as Athens, to their Sourcegraph instance so that users can search and navigate the repositories.
To add Go dependencies to Sourcegraph you need to setup a Go dependencies code host:
- As site admin: go to Site admin > Global settings and enable the experimental feature by adding:
{"experimentalFeatures": {"goPackages": "enabled"} }
- As site admin: go to Site admin > Manage code hosts
- Select JVM Dependencies.
- Configure the connection by following the instructions above the text field. Additional fields can be added using
Cmd/Ctrl+Space
for auto-completion. See the configuration documentation below. - Press Add repositories.
Repository syncing
There are currently two ways to sync Go dependency repositories.
- Code host configuration: manually list dependencies in the
"dependencies"
section of the JSON configuration when creating the Go dependency code host. This method can be useful to verify that the credentials are picked up correctly without having to run a dependencies search.
Sourcegraph tries to find each dependency repository in all configured "urls"
until it's found. This means you can configure a public proxy first and fallback to a private one second (e.g. "urls": ["https://proxy.golang.org", "https://admin:[email protected]"]
).
Credentials
Each entry in the "urls"
array can contain basic auth if needed (e.g. https://user:[email protected]
).
Rate limiting
By default, requests to the Go module proxies will be rate-limited based on a default internal limit. (source)
JSON"rateLimit": { "enabled": true, "requestsPerHour": 57600.0 }
where the requestsPerHour
field is set based on your requirements.
Not recommended: Rate-limiting can be turned off entirely as well. This increases the risk of overloading the proxy.
JSON"rateLimit": { "enabled": false }
Configuration
Go dependencies code host connections support the following configuration options, which are specified in the JSON editor in the site admin "Manage code hosts" area.
admin/code_hosts/go-modules.schema.json
JSON{ // An array of strings specifying Go modules to mirror in Sourcegraph. "dependencies": null, // Other example values: // - [ // "cloud.google.com/go/[email protected]" // ] // Rate limit applied when making background API requests to the configured Go module proxies. "rateLimit": { "enabled": true, "requestsPerHour": 57600 }, // The list of Go module proxy URLs to fetch modules from. 404 Not found or 410 Gone responses will result in the next URL to be attempted. "urls": [ "https://proxy.golang.org" ] // Other example values: // - [ // "https://athens.mycorp.org", // "https://proxy.golang.org" // ] }