Golang构建命令如何查找私有GitLab仓库
Golang构建命令如何查找私有GitLab仓库 我在使用 go.mod 和私有 GitLab 仓库时遇到了困难。当我尝试构建项目时,go 试图下载我的仓库并收到 410 Gone 错误。
系统:
windows 10
我的项目结构:
私有仓库: gitlam.com/me/private
结构:
pkg1
pkg2
cmd
|_prj
|_main.go
go.mod
go.sum
我在 private/cmd/prj1 目录下工作。
go.mod:
module gitlab.com/me/private
go 1.13.4
我尝试过的:
- 设置 GOPRIVATE=gitlab.com/me/private
- 设置 GOPRIVATE=gitlab.com/me/private/*
- 设置 GONOPROXY=gitlab.com/me/private
- 设置 GONOPROXY=gitlab.com/me/private/*
- 设置 GONOSUMDB=
- 设置 GONOSUMDB=gitlab.com/me/private
- 设置 GONOSUMDB=gitlab.com/me/private/*
- git config --global url.“https://me:${personal-access-token}@gitlab.com/me/private”.insteadOf “https://gitlab.com/me/private”
- git config --global url.“https://me:${personal-access-token}@gitlab.com/me/private.git”.insteadOf “https://gitlab.com/me/private.git”
- _netrc/.netrc 配置
每次都是同样的 410 错误……我已经没有主意了。也许有人有解决方案?或者 go 不支持在私有仓库的 cmd 文件夹中工作?
更多关于Golang构建命令如何查找私有GitLab仓库的实战教程也可以访问 https://www.itying.com/category-94-b0.html
很高兴看到现在一切如预期般正常运行。 请将该问题标记为已解决。点击灰色的勾选框。
更多关于Golang构建命令如何查找私有GitLab仓库的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html
我想我找到了解决方案 😊
在 cmd/prj 目录下添加 go.mod 文件,并加入这行代码:
replace gitlab.com/me/private => ../../
注意! /path/to/repository 必须包含 go.mod 文件。查看文档。
不清楚您想要实现什么。
如果您希望包不从 proxy.golang.org 下载,那么 set GOPRIVATE=gitlab.com/me/private 应该就足够了。这就是 GOPRIVATE 环境变量的目的。请参阅 go help module-private。
您是否正在从这个私有仓库导入包?
为了测试您的问题,我创建了一个新项目,其 go.mod 模块名为 gitlab.com/me/private。
在项目中,我创建了一个名为 pkg1 的包,并在 cmd/app 目录中创建了一个 main.go 文件。main 函数调用了该包中的一个函数。导入路径是 gitlab.com/me/private/pkg1。
我使用命令 GOPRIVATE="gitlab.com/me/private" go build ./cmd/app 来构建它。
它静默地编译成功,存储在 go.mod 文件旁边的名为 app 的可执行文件按预期运行。如您所见,go build 不需要访问 gitlab 仓库来构建项目。所以我不明白问题出在哪里,以及为什么您需要这个 replace 指令。我不需要它。


