Contents

Dependency issue golang Module in Gitlab

Manage dependency in golang is quite easy, the module path like git.company.com/product/tools/adapter/db/mongo can

When you hosting your code privately in gitlab.com or your company (e.g: git.company.com)

Most of the time people who using github.com as their base for Go module don’t have this issues. How do you get it work with Go modules (privately!)

Common issue for private module, triggered by go mod tidy

1
2
3
fatal: unable to update url base from redirection:
25 	  asked for: http://git.company.com/product/tools.git/info/refs?service=git-upload-pack
26 	   redirect: https://git.company.com/users/sign_in

Create access token for gitlab authorization

The details you can read details here Create access token here https://git.company.com/profile/personal_access_tokens

/2021/09/dependency-issue-golang-module-in-gitlab/images/personal-access-token.png
Make sure check api and read repository

Create or edit netrc file

On linux/Mac the location is on ~/.netrc on windows is on ~/_netrc

Here’s the contents:

1
2
3
machine git.company.com
login yourUserName
password YourPersonalAccessToken

Set GOPRIVATE on

go env -w GOPRIVATE=git.company.com

Set Redirect properly for git

1
2
3
git config --global url.https://oauth2:[email protected] git.company.com

git config --global url.https://oauth2:[email protected] http://git.company.com

This command will force git to always redirect to https