Updated on 2026-08-10 GMT+08:00

Uploading and Downloading a Go Package on the Client

CodeArts Artifact can connect to local Go clients. You may upload your private packages from your local Go client to self-hosted repos and share them with others, who can download these Go packages through their clients.

Go Package

Go (Golang) packages are packages or applications developed and published using the Go programming language. These packages can be libraries (library packages) or executable files (binary files).

Constraints

The repository password for a self-hosted repo is account-specific. If you are prompted for a password while using a different account, download the configuration file from the repository's Tutorial tab to obtain it.

Prerequisites

  • The client tool is Go. Ensure that V1.13 or a later version has been installed and the project is a Go module project.
  • You have created a Go repository.
  • You have the Download/View permission on the current repository. For details about how to obtain this permission, see Configuring Repository Permissions.

Uploading a Go Package from the Client

  • Go Modules packaging and package upload

    This section describes how to build and upload Go packages through Go modules. The username and password used in the following steps can be obtained from the downloaded configuration file for the Go repository.

    Perform the following steps:

    1. Create a source folder in the working directory.
      mkdir -p {module}@{version}
    2. Copy the code source to the source folder.
      cp -rf . {module}@{version}
    3. Compress the package into a ZIP package.
      zip -D -r [package name] [package root directory]
    4. Upload the ZIP package and the go.mod file to the self-hosted repo.
      curl -k -u {{username}}:{{password}} -X PUT {{repoUrl}}/{filePath} -T {{localFile}}

      The package directory varies according to the package version. The version can be:

      • Versions earlier than v2.0: The directory is the same as the path of the go.mod file. No special directory is required.
      • v2.0 or later:
        • If the first line in the go.mod file ends with /vX, the directory must contain /vX. For example, if the version is v2.0.1, the directory must contain v2.
        • If the first line in the go.mod file does not end with /vN, the directory remains unchanged and the name of the file to be uploaded must contain +incompatible.

        The following are examples of package directories for different versions:

    Versions earlier than v2.0

    The go.mod file is used as an example.

    1. Create a source folder in the working directory.

      The value of module is example.com/demo and that of version is 1.0.0. The command is as follows.

      mkdir -p ~/example.com/demo@v1.0.0
    2. Copy the code source to the source folder.

      The command is as follows (with the same parameter values as the previous command).

      cp -rf . ~/example.com/demo@v1.0.0/
    3. Compress the package into a ZIP package.

      Run the following command to go to the upper-level directory of the root directory where the ZIP package is located:

      cd ~

      Then, use the zip command to compress the code into a package. In this command, the package root directory is example.com and the package name is v1.0.0.zip. The command is as follows.

      zip -D -r v1.0.0.zip  example.com/
    4. Upload the ZIP package and the go.mod file to the self-hosted repo.

      Parameters username, password, and repoUrl can be obtained from the configuration file.

      • For the ZIP package, the value of filePath is example.com/demo/@v/v1.0.0.zip and that of localFile is v1.0.0.zip.
      • For the go.mod file, the value of filePath is example.com/demo/@v/v1.0.0.mod and that of localFile is example.com/demo@v1.0.0/go.mod.

      The commands are as follows (replace username, password, and repoUrl with the actual values).

      curl -k -u {{username}}:{{password}} -X PUT {{repoUrl}}/example.com/demo/@v/v1.0.0.zip -T v1.0.0.zip
      curl -k -u {{username}}:{{password}} -X PUT {{repoUrl}}/example.com/demo/@v/v1.0.0.mod -T example.com/demo@v1.0.0/go.mod

  • v2.0 and later, with the first line in the go.mod file ends with /vX.

    The go.mod file is used as an example.

    1. Create a source folder in the working directory.

      The value of module is example.com/demo/v2 and that of version is 2.0.0. The command is as follows.

      mkdir -p ~/example.com/demo/v2@v2.0.0
    2. Copy the code source to the source folder.
      The command is as follows (with the same parameter values as the previous command).
      cp -rf . ~/example.com/demo/v2@v2.0.0/
    3. Compress the package into a ZIP package.

      Run the following command to go to the upper-level directory of the root directory where the ZIP package is located:

      cd ~

      Then, use the zip command to compress the code into a package. In this command, the package root directory is example.com and the package name is v2.0.0.zip. The command is as follows.

      zip -D -r v2.0.0.zip  example.com/
    4. Upload the ZIP package and the go.mod file to the self-hosted repo.

      Parameters username, password, and repoUrl can be obtained from the configuration file.

      • For the ZIP package, the value of filePath is example.com/demo/v2/@v/v2.0.0.zip and that of localFile is v2.0.0.zip.
      • For the go.mod file, the value of filePath is example.com/demo/v2/@v/v2.0.0.mod and that of localFile is example.com/demo/v2@v2.0.0/go.mod.

      The commands are as follows (replace username, password, and repoUrl with the actual values).

      curl -u {{username}}:{{password}} -X PUT {{repoUrl}}/example.com/demo/v2/@v/v2.0.0.zip -T v2.0.0.zip
      curl -u {{username}}:{{password}} -X PUT {{repoUrl}}/example.com/demo/v2/@v/v2.0.0.mod -T example.com/demo/v2@v2.0.0/go.mod
  • v2.0 and later, with the first line in the go.mod file does not end with /vX.

    The go.mod file is used as an example.

    1. Create a source folder in the working directory.

      The value of module is example.com/demo and that of version is 3.0.0. The command is as follows.

      mkdir -p ~/example.com/demo@v3.0.0+incompatible
    2. Copy the code source to the source folder.

      The command is as follows (with the same parameter values as the previous command).

      cp -rf . ~/example.com/demo@v3.0.0+incompatible/
    3. Compress the package into a ZIP package.

      Run the following command to go to the upper-level directory of the root directory where the ZIP package is located:

      cd ~

      Then, use the zip command to compress the code into a package. In this command, the package root directory is example.com and the package name is v3.0.0.zip. The command is as follows.

      zip -D -r v3.0.0.zip  example.com/
    4. Upload the ZIP package and the go.mod file to the self-hosted repo.

      Parameters username, password, and repoUrl can be obtained from the configuration file.

      • For the ZIP package, the value of filePath is example.com/demo/@v/v3.0.0+incompatible.zip and that of localFile is v3.0.0.zip.
      • For the go.mod file, the value of filePath is example.com/demo/@v/v3.0.0+incompatible.mod and that of localFile is example.com/demo@v3.0.0+incompatible/go.mod.

      The commands are as follows (replace username, password, and repoUrl with the actual values).

      curl -k -u {{username}}:{{password}} -X PUT {{repoUrl}}/example.com/demo/@v/v3.0.0+incompatible.zip -T v3.0.0.zip
      curl -k -u {{username}}:{{password}} -X PUT {{repoUrl}}/example.com/demo/@v/v3.0.0+incompatible.mod -T example.com/demo@v3.0.0+incompatible/go.mod

Downloading a Go Package to the Client

Certificate verification cannot be bypassed on the Go client. You need to add the domain name certificate corresponding to the self-hosted repo to the local certificate trust list and perform the following steps to add the trust certificate:

  1. Export the certificates.

    openssl s_client -connect {host}:443 -showcerts </dev/null 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' |openssl x509 -outform PEM >mycertfile.pem
    openssl x509 -outform der -in mycertfile.pem -out mycertfile.crt

    mycertfile.pem and mycertfile.crt are the downloaded certificates.

  2. Add the certificates to the root certificate trust list.
  3. Run the go commands to download the dependency.

    ##1. v2.0 and earlier versions
    go get -v <moudlename>
    ##2. v2.0 and later versions
    ##a. The ZIP package contains go.mod and the path ends with /vN.
    go get -v {{moduleName}}/vN@{{version}}
    ##b. The ZIP package does not contain go.mod or the first line in go.mod does not end with /vN.
    go get -v {moduleName}}@{{version}}+incompatible