英文:
Module lookup disabled by GOPROXY=off golangci
问题
我有一个供应商文件夹和一个 CI/CD 任务的 Linter。在将文件夹推送到 GitLab 之前,我执行了以下操作:
go mod tidy
go mod vendor
我的 Makefile 中的 Linter 任务如下:
@GO111MODULE=on GOFLAGS=-mod=vendor GOPROXY=off $(GOLINT) run ./... -v --max-same-issues 0
在本地启动 Linter 时,我没有任何问题。但是在 CI/CD 过程中,我遇到了一个错误:
> 运行错误:上下文加载失败:加载包失败:使用 go/packages 加载失败:错误:退出状态 1:stderr:go:
> github.com/jmoiron/sqlx@v1.3.1: 由于 GOPROXY=off,模块查找被禁用
所以我不明白为什么会出现这个错误
更新
我决定删除 vendor、go.mod 和 go.sum。然后我创建了新的 go.mod 并执行了以下操作:
go mod vendor
之后,我遇到了同样的错误,但是是关于另一个包的错误:
> level=error msg="运行错误:上下文加载失败:加载包失败:使用 go/packages 加载失败:错误:退出状态 1:stderr:
> go: github.com/fsnotify/fsnotify@v1.5.1: 由于 GOPROXY=off,模块查找被禁用
英文:
I have a vendor folder and CI/CD task Linter. Before push the folder to gitlab I did
go mod tidy
go mod vendor
My Linter task in Makefile looks like
@GO111MODULE=on GOFLAGS=-mod=vendor GOPROXY=off $(GOLINT) run ./... -v --max-same-issues 0
and I have no any problems when I start linting locally. But during CI/CD I got an error
> Running error: context loading failed: failed to load packages: failed
> to load with go/packages: err: exit status 1: stderr: go:
> github.com/jmoiron/sqlx@v1.3.1: module lookup disabled by GOPROXY=off
So i can't understand why I got this error
Update
I decided to remove the vendor, go.mod and go.sum. Then I created new go.mod and did
go mod vendor
After that I got the same error but with another package
> level=error msg="Running error: context loading failed: failed to load
> packages: failed to load with go/packages: err: exit status 1: stderr:
> go: github.com/fsnotify/fsnotify@v1.5.1: module lookup disabled by
> GOPROXY=off
答案1
得分: 0
问题出在golangci的modules-download-mode设置上。
解决方法是将该变量设置为vendor模式:
modules-download-mode: vendor
英文:
The problem was in the settings of golangci modules-download-mode
this solution is set this variable to vendor mode:
modules-download-mode: vendor
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论