Skip to main content

Go CLI Usage

This page describes common CLI commands to download, resolve and publish Go modules through Sonatype Nexus Repository.

After you configure Go with Nexus, use standard Go commands to resolve, download, and verify modules through your Nexus repository.

Download a Module

After configuring Go with Nexus, run Go commands as usual from your workspace. The following command fetches the dependency through the configured Nexus endpoint.

go get <MODULE_PATH>@<VERSION>

Where,

  • <MODULE_PATH - The module path of the Go package

  • <VERSION> - The module version

Example:

go get github.com/user_account/[email protected]

Resolve Dependencies

Use go mod tidy to resolve the full transitive dependency graph and update module metadata.

When your client is configured to use Nexus, transitive dependencies are also resolved through the configured Go repository.

Upload a Module

Use the REST API to upload modules to a Nexus hosted repository.

The module archive must contain files under a top-level directory named <MODULE_PATH>&<VERSION>/.

Example archive structure:

v1.0.6.zip
└── github.maif.io/forge-tnr/[email protected]/
    ├── go.mod
    ├── go.sum
    └── greetings.go
mkdir -p "github.maif.io/forge-tnr/[email protected]"
cp go.mod go.sum greetings.go "github.maif.io/forge-tnr/[email protected]/"
zip -r v1.0.6.zip "github.maif.io/forge-tnr/[email protected]"
curl -u <USERNAME>:<PASSWORD> \
  -X PUT \
  "https://<NEXUS_URL>/repository/<REPOSITORY_NAME>/<VERSION>.zip" \
  --upload-file <MODULE_ARCHIVE>.zip

Where,

  • <USERNAME> - Your Nexus username or user token name code

  • <PASSWORD> - Your Nexus password or user token pass code

  • <NEXUS_URL> - Your Nexus instance URL

  • <REPOSITORY_NAME> - Your Nexus hosted repository name

  • <VERSION> - The module version

Example:

curl -u admin:admin123\
  -X PUT \
  "https://example.nexus.com/repository/go-hosted/v1.2.3.zip" \
  --upload-file [email protected]