Skip to main content
Harness Artifact Registry provides native support for Go modules, allowing you to host private Go packages and dependencies.

Overview

Go registry features:
  • Standard Go module proxy protocol
  • Automatic .mod, .info, and .zip file generation
  • Version management following Go module versioning
  • Private module authentication

Pushing Go modules

Use the hc artifact push go command to publish Go modules:
hc artifact push go <registry-name> <folder-path> \
  --version <version> \
  --pkg-url <pkg-url>

Required flags

--version
string
required
Version for the Go module (must follow semantic versioning, e.g., v1.0.0)

Optional flags

--pkg-url
string
Base URL for the package service. If not provided, derives from --api-url

How it works

The CLI automatically:
  1. Validates the folder contains valid Go source code
  2. Generates the .mod file from go.mod
  3. Creates the .info file with version metadata
  4. Packages source code into a .zip file
  5. Uploads all three files as a multipart form request
1

Prepare your module

Ensure your Go module has a valid go.mod file:
module github.com/myorg/mymodule

go 1.21

require (
    github.com/pkg/errors v0.9.1
)
2

Push to registry

Upload your module:
hc artifact push go my-go-registry ./mymodule \
  --version v1.0.0 \
  --pkg-url https://app.harness.io/registry/pkg
3

Configure Go to use your registry

Set up Go to fetch from your private registry:
export GOPRIVATE=<registry-url>/*
export GOPROXY=https://<registry-url>,https://proxy.golang.org,direct

Consuming Go modules

After configuring your Go environment, import modules as usual:
import "<registry-url>/myorg/mymodule"
Go will automatically fetch from your Harness registry.

Authentication

Configure Git credentials for private module access:
# Using .netrc for authentication
cat >> ~/.netrc <<EOF
machine <registry-url>
login <username>
password <harness-api-token>
EOF

chmod 600 ~/.netrc
Or use Git credential helper:
git config --global credential.helper store
echo "https://<username>:<token>@<registry-url>" >> ~/.git-credentials

Examples

hc artifact push go my-go-registry ./my-library \
  --version v1.0.0 \
  --pkg-url https://app.harness.io/registry/pkg

Version requirements

Go module versions must follow semantic versioning with a v prefix (e.g., v1.0.0, v2.1.3-beta.1)
Valid version formats:
  • v1.0.0 - Standard release
  • v2.1.0-alpha.1 - Pre-release
  • v1.0.0+build.123 - Build metadata

Troubleshooting

The --version flag is mandatory for Go module uploads.
# ❌ Wrong
hc artifact push go my-registry ./module

# ✅ Correct
hc artifact push go my-registry ./module --version v1.0.0
Ensure your folder contains a valid go.mod file at the root:
mymodule/
├── go.mod      # Required
├── go.sum
├── main.go
└── pkg/
Verify your credentials are configured correctly:
# Check authentication
hc auth status

# Re-login if needed
hc auth login --api-key <your-key>

See also

Build docs developers (and LLMs) love