Home > Backend Development > Golang > How to Use `go get` or `go dep` with Private GitLab Subgroups?

How to Use `go get` or `go dep` with Private GitLab Subgroups?

DDD
Release: 2024-12-03 00:13:19
Original
963 people have browsed it

How to Use `go get` or `go dep` with Private GitLab Subgroups?

Using 'go get' or 'go dep' with GitLab Subgroups

When attempting to retrieve dependencies from a private GitLab repository using 'go get' or 'go dep', you may encounter an error indicating that the remote repository is inaccessible. This issue is due to security measures implemented for private repositories on GitLab.

According to the GitLab support tracker, the recommended solution is to explicitly include .git in the URL when using 'go get' or 'go dep'. However, a more comprehensive solution that addresses both dependency managers and modern Go modules is to leverage 'go get's' support for .netrc.

Step-by-Step Solution:

  1. Create a Personal Access Token on GitLab:

    • Obtain a token with the 'api' scope.
  2. Create a ~/.netrc File:

    • Add the following content to the file:

      machine gitlab.com
      login <your gitlab username>
      password <the token created in step 1>
      Copy after login
  3. Protect the .netrc File:

    • Use the following command to restrict access:

      chmod 600 ~/.netrc
      Copy after login

Usage:

After completing these steps, you should be able to successfully retrieve dependencies using either 'go get' or 'go dep':

  • Using 'go get':

    go get gitlab.com/<company>/<subgroup>/<project>
    Copy after login
  • Using 'go dep':

    dep ensure -add gitlab.com/<company>/<subgroup>/<project>
    Copy after login

Note:

If you are using a private GitLab installation, replace gitlab.com with the appropriate hostname in the provided commands.

The above is the detailed content of How to Use `go get` or `go dep` with Private GitLab Subgroups?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template