golint 在已成功下载的 Go mod 依赖项中遇到问题
时间:2024-03-02
浏览:199
作者:佚名
在IT行业这个发展更新速度很快的行业,只有不停止的学习,才不会被行业所淘汰。如果你是Golang学习者,那么本文《golint 在已成功下载的 Go mod 依赖项中遇到问题》就很适合你!本篇内容主要包括##content_title##,希望对大家的知识积累有所帮助,助力实战开发!
在 gitlab ci 中,我需要指定 gitlab_deploy_token,因为我有一些私有存储库。这对于编译步骤来说效果很好。
但是当我执行 golint 时,它会再次下载所有依赖项,并且在私有依赖项上会失败。我可以添加相同的 git config 指令,
图片:golang 变量: package_path:/go/src/gitlab.com/company/sam/daemon package_api_name:registry.gitlab.com/company/sam/daemon registry_url:https://registry.gitlab.com docker_driver:覆盖 go111module:“开”
.锚点: -&注入-gopath mkdir -p $(目录名${package_path}) && ln -s ${ci_project_dir} ${package_path} && cd ${package_path}
compile:
stage: build
before_script:
- *inject-gopath
- git config --global url."https://oauth:${GITLAB_DEPLOY_TOKEN}@gitlab.com".insteadOf https://gitlab.com
- go mod tidy
script: GOOS=linux GOARCH=arm GOARM=7 go build -o release/daemon .
artifacts:
name: "binary-$CI_PIPELINE_ID"
paths:
- $GOPATH/pkg/mod/
expire_in: 1 hour
lint:
stage: test
before_script:
- apt install -y curl git
- go get github.com/golang/lint
- *inject-gopath
script:
- $GOPATH/bin/golint -set_exit_status $(go list ./...)
allow_failure: true
我在这里读到 go 模块缓存在 $gopath/pkg/mod 中,但它似乎不起作用
知道我应该如何解决它吗?
解决方案
gitlab 将所有路径解释为相对于项目根目录,因此如果您的项目是 myproject,则 $gopath/pkg/mod/ 会翻译为 myproject/$gopath/pkg/mod/,但是 go 工具所在的位置实际上实际安装的软件包是 /$gopath/pkg/mod/ (直接在 root 下)。
您可以通过将 gopath 设置为项目目录中的某个位置来解决此问题;例如
export GOPATH="$CI_PROJECT_DIR/pkg/mod"
然后,您可以在整个管道中使用此路径。
今天关于《golint 在已成功下载的 Go mod 依赖项中遇到问题》的内容介绍就到此结束,如果有什么疑问或者建议,可以在golang学习网公众号下多多回复交流;文中若有不正之处,也希望回复留言以告知!
本文内容来源于互联网,如有侵权请联系删除。
近期热门
站内热门
最新文章
热门专题
