Skip to content

Working with Go

CodeScoring.Save implements Go Module Proxy Protocol with the /go/<project>/<repository>/ prefix. It is compatible with the standard Go toolchain (go mod, go build, go install).

Proxy Repository

curl -X POST https://save.example.com/api/v1/repos \
  -H "Content-Type: application/json" \
  -u "<username>:<password>" \
  -d '{
    "project": "backend",
    "name": "go-proxy",
    "format": "go",
    "repository_type": "proxy",
    "remote_url": "https://proxy.golang.org",
    "cache_ttl": 86400
  }'

Hosted Repository

curl -X POST https://save.example.com/api/v1/repos \
  -H "Content-Type: application/json" \
  -u "<username>:<password>" \
  -d '{
    "project": "backend",
    "name": "go-hosted",
    "format": "go",
    "repository_type": "hosted"
  }'

A hosted repository accepts PUT uploads of modules at URLs like:

PUT /go/<project>/go-hosted/<module>/@v/<version>.zip

Module paths use case encoding according to the Go Module Proxy spec: uppercase letters are replaced with ! + the corresponding lowercase letter, for example Acme -> !acme.

Client Configuration

# Set GOPROXY
export GOPROXY="https://save.example.com/go/<project>/go-proxy"

# If Basic Auth is used, credentials are passed through .netrc:
cat >> ~/.netrc << EOF
machine save.example.com
login <username>
password <password>
EOF
chmod 600 ~/.netrc

Proxy chain

GOPROXY can contain several URLs separated by commas: GOPROXY="https://save.example.com/go/<project>/go-proxy,direct". The Go toolchain tries each proxy in order; direct means direct access to VCS.

Robot accounts in CI

For CI/CD, use a robot account: login = sa$<robot-name>, password = <api-key> in ~/.netrc. For details, see Authentication.

GOPRIVATE for internal modules

If the repository stores internal modules that are not present in public sumdb, add their patterns to GOPRIVATE.

export GOPRIVATE="git.example.com/*"
# If needed, sumdb can be disabled completely:
# export GOSUMDB=off

Repository URL Migration

Use case: migrating a Go proxy from Nexus / Artifactory to CodeScoring.Save.

Source GOPROXY before migration GOPROXY after migration
Nexus https://nexus.host.ru/repository/go-remote https://save.example.com/go/<project>/go-proxy
Artifactory https://jfrog.host.ru/artifactory/api/go/go-virt https://save.example.com/go/<project>/go-proxy
Official proxy https://proxy.golang.org https://save.example.com/go/<project>/go-proxy

Troubleshooting

Checking Version List

curl -u "<username>:<password>" \
  https://save.example.com/go/<project>/go-proxy/github.com/gin-gonic/gin/@v/list

Service Status

curl https://save.example.com/health

Repository Audit

curl -u "<username>:<password>" \
  "https://save.example.com/api/v1/admin/audit?resource_type=repository&q=go-proxy&limit=50"
Страница была полезна?