Featured image of post Getting Started Go Project on private repository

Getting Started Go Project on private repository

I got problem when try to uninstall sass installed from ruby, and this is how I solve it.

The story began when i have difficuly to start golang project from private repository. I cloned the repository and tried to run go mod tidy but it failed even though I can clone the repository. Also the IDE throw broken import error.

here is the log:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
        go.opentelemetry.io/otel/sdk/metric/metricdata: gitlab.company_name.com/private_project/company_name-proto@v1.2.1: reading gitlab.company_name.com/private_project/company_name-proto/go.mod at revision v1.2.1: git ls-remote -q origin in /Users/mw/go/pkg/mod/cache/vcs/18d782c18bf7767ce23fe2f51f4a1f47108e42757838f9b557e947316e465ef0: exit status 128:
        remote: HTTP Basic: Access denied. The provided password or token is incorrect or your account has 2FA enabled and you must use a personal access token instead of a password. See https://gitlab.company_name.com/help/topics/git/troubleshooting_git#error-on-git-fetch-http-basic-access-denied
        fatal: Authentication failed for 'https://gitlab.company_name.com/private_project/company_name-proto.git/'
go: gitlab.company_name.com/private_project/xyz/xyz-logic/internal/infrastructure/grpcserver imports
        google.golang.org/grpc imports
        google.golang.org/grpc/balancer/pickfirst imports
        google.golang.org/grpc/balancer/pickfirst/pickfirstleaf tested by
        google.golang.org/grpc/balancer/pickfirst/pickfirstleaf.test imports
        go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest: gitlab.company_name.com/private_project/company_name-proto@v1.2.1: reading gitlab.company_name.com/private_project/company_name-proto/go.mod at revision v1.2.1: git ls-remote -q origin in /Users/mw/go/pkg/mod/cache/vcs/
        remote: HTTP Basic: Access denied. The provided password or token is incorrect or your account has 2FA enabled and you must use a personal access token instead of a password. See https://gitlab.company_name.com/help/topics/git/troubleshooting_git#error-on-git-fetch-http-basic-access-denied
        fatal: Authentication failed for 'https://gitlab.company_name.com/private_project/company_name-proto.git/'
go: gitlab.company_name.com/private_project/xyz/xyz-logic/internal/application/creditcontrol tested by
        gitlab.company_name.com/private_project/xyz/xyz-logic/internal/application/creditcontrol.test imports
        github.com/stretchr/testify/assert imports
        github.com/stretchr/testify/assert/yaml imports
        gopkg.in/yaml.v3 tested by
        gopkg.in/yaml.v3.test imports
        remote: HTTP Basic: Access denied. The provided password or token is incorrect or your account has 2FA enabled and you must use a personal access token instead of a password. See https://gitlab.company_name.com/help/topics/git/troubleshooting_git#error-on-git-fetch-http-basic-access-denied
        fatal: Authentication failed for 'https://gitlab.company_name.com/private_project/company_name-proto.git/'

the are two steps that i need to do to fix this problem:

  1. Update GOPRIVATE environment variable to include the private repository domain.
    • check the GOPRIVATE value by running go env GOPRIVATE
    • if the value is empty, set it to the private repository domain, e.g. go env -w GOPRIVATE=gitlab.company_name.com
    • you can undo this by running go env -u
    • more detail see go help env
  2. Telling Git to rewrite the URL for your private GitLab repository, which forces it to use SSH authentication instead of HTTPS.
    • example: git config --global url.git@gitlab.company_name.com:.insteadOf https://gitlab.company_name.com/
    • The insteadOf configuration tells Git: “Every time you see a URL that starts with https://gitlab.company_name.com/, replace that prefix with git@gitlab.company_name.com:.”
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus