go-quickstart
Last updated on
Prerequisites
- Ensure you have Go installed and configured on your local machine.
additional information
Depending on your environment, you may need to run additional commands. Go to the Go installation guide for more information.
- Ensure you have access to a Harness account with the appropriate permissions to create registries and connectors.
- Ensure you have Harness CLI installed and running in your local machine.
Create a Go Artifact Registry
- Interactive Guide
- Step-by-Step
- Navigate to the Artifact Registry module in your Harness project.
- Click on New Artifact Registry.
- In the Registry Type list, select Go Registry.
- Provide a Registry Name.
- The registry name must start with a letter and can include lowercase alphanumeric characters, underscores (
_), periods (.), and hyphens (-).
- The registry name must start with a letter and can include lowercase alphanumeric characters, underscores (
- Optionally, add a Description and Labels for better organization.
- Choose visibility between Public and Private.
- Click Create Registry to finalize.
private go registry
This registry will serve as your private Go registry within Harness.
Configure an Upstream Proxy (Optional)
An upstream proxy allows your registry to fetch Go modules from external sources if they are not available locally.
- Interactive Guides
- Step-by-Step
Create an upstream proxy
Configure the upstream proxy in your registry
Create an upstream proxy
- In the Artifact Registry module, click the dropdown next to New Artifact Registry and select Upstream Proxy.
- Choose Go Registry as the proxy type.
- Click Create Proxy to establish the connection.
Configure the upstream proxy in your registry
- In the Artifact Registry module, select an existing Go Artifact Registry.
- Select the Configuration tab.
- Under Advanced (Optional), select Configure Upstream.
- Select from the list of compatible proxies to add them to your registry.
- Click Save to save the configuration.
upstream proxy caching
If a Go module isn’t found in your Harness registry, the upstream proxy fetches it from an external registry like proxy.golang.org, reducing duplication and improving module resolution.
Publish & Install Go modules
Authenticate the Go client
- In your Harness Go Artifact Registry, click Setup Client.
- Click Generate Token to generate an identity token.
- Export your token with the following command:
export GOPROXY="https://<email_address>:<TOKEN>@pkg.app.harness.io/pkg/<harness_account_id>/<go-registry-name>/go"
Publish a Go package
- Run the following command (using Harness CLI) from your project’s root directory to publish your Go package into your Harness Registry:
hns ar push go <REGISTRY_NAME> <ARTIFACT_VERSION> --pkg-url pkg.app.harness.io
Install a Go package
- Install your package using
go get:
go get <ARTIFACT_NAME>@<VERSION>
Troubleshooting
- Slow downloads or timeouts. Verify network egress to the Harness endpoint. If needed, configure
GOPROXYexplicitly and ensure your client respects it. - Authentication errors. Ensure your
go env -w GOPRIVATEand token setup are correctly applied. - Package not found. Confirm the package was published to the correct Harness registry and that the version tag exists in the repository.