根据this document我需要将 -mod=vendor
添加到我的构建命令中以使用我的本地 vendor
文件夹:
By default, go commands like go build ignore the vendor directory when in module mode. The -mod=vendor flag (e.g., go build -mod=vendor) instructs the go commands to use the main module's top-level vendor directory to satisfy dependencies.
当我运行此命令时:
go build -mod=vendor -a -ldflags "-s -w -X github.com/my-api/pkg/config.Version=169.3988801" -o bin/my-api
我收到此错误:
build flag -mod=vendor only valid when using modules
在本地,该命令按预期工作,错误仅发生在构建服务器上。
最佳答案
我认为您所显示的帮助的关键部分是处于模块模式时
。仅当您在 GOPATH 之外处理代码或设置了 GO111MODULE=on 环境变量时才会发生这种情况,因此我认为您在本地环境中设置了此设置,但在构建服务器中没有设置。
有关启用模块支持的更多信息如下:
关于go - 错误: "build flag -mod=vendor only valid when using modules" when building Go project,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55662147/