gitlab subgroup use go.mod

1,052 阅读1分钟

How to use Go dep with GitLab subgroups

背景:要拆分项目公共组件,导致go mod 不可避免使用私有仓库的subgroup下面的三方库

现象:每个引用都得用replace

初始怀疑是gitlab版本低的问题

在本地docker启动gitlab-ce 13.8.1 ,无效

使用官方gitlab.com-cc 13.10.0 无效

解决方案

  1. go env -w GOPRIVATE=gitlabxa.uniontech.com
  2. go clean -modcache 清除缓存
  3. 获取一个gitlab Personal Access Tokens (权限是api或者全选)
  4. 创建 ~/.netrc
machine gitlabxa.uniontech.com
    login <your gitlab username>
    password <the token created in step 3>
  1. chmod 600 ~/.netrc
  2. go mod tidy

参考: