When downloading packages, Go checks the public Go Checksum Database to verify the package checksum. Private Git packages, such as those on a private GitLab instance, aren’t in that database, so downloading them will fail.

This can be fixed by setting GOPRIVATE=private.example.com. This instructs Go not to check the Checksum Database for packages in the private.example.com domain.

For GitLab, first set up access to repositories:

  1. Create a GitLab Access Token with the read_api scope.
  2. Update your ${HOME}/.netrc file, and add:
machine private.example.com
    login your.email@example.com
    password gitlab_access_token

More information can be found in the GitLab documentation.

Then, set up the IDE to work with private Git packages.

GoLand

Go to Settings → Go → Go Modules and add GOPRIVATE=private.example.com.

VS Code

Add the following to your settings:

"go.toolsEnvVars": {
    "GOPRIVATE": "private.example.com"
}