【问题标题】:Govendor is not importing newer versionsgovendor 不导入较新的版本
【发布时间】:2019-12-07 00:22:15
【问题描述】:

golang.org/x/net/html 的旧版本具有vulnerabilities。哎呀!更好地升级软件包。两年前,我们使用govendor 建立了我们的 Shopify 集成项目;所以让我们使用govendor来升级:

ip-192-168-3-40:Shopify-Gateway username$ git diff
ip-192-168-3-40:Shopify-Gateway username$ govendor fetch golang.org/x/net/html
ip-192-168-3-40:Shopify-Gateway username$ git diff
ip-192-168-3-40:Shopify-Gateway username$

Govendor 什么也没做!这是fetch之后的vendor.json文件:

    {
        "checksumSHA1": "vqc3a+oTUGX8PmD0TS+qQ7gmN8I=",
        "path": "golang.org/x/net/html",
        "revision": "d997483c6db05184c79c182674d01f1e7b7553ae",
        "revisionTime": "2017-05-30T13:01:13Z"
    },

这是一个相当旧的修订版,肯定比 2018 年 9 月 25 日发布的漏洞修复更早。Govendor 是一个较旧的软件包,似乎不再维护。我必须更换govendor吗?有天然替代品吗?还是我做错了什么导致我无法更新我的包?

版本信息:

ip-192-168-3-40:Shopify-Gateway username$ govendor --version v1.0.9
ip-192-168-3-40:Shopify-Gateway username$ go version
go version go1.13.1 darwin/amd64

编辑:许多人建议使用 go 模块。我们不能使用它们!我们依赖于未版本化的依赖项,当我们尝试将包升级到 go modules 时,此依赖项会下降到较低版本,从而引入数据库安全漏洞。我需要能够就地更新软件包,因为它们是由 govendor 安装的。

我还尝试安装我想使用的 govendor 软件包的特定版本号:

ip-192-168-3-40:Shopify-Gateway username$ govendor fetch golang.org/x/net/html@d26f9f9a57f3fab6a695bec0d84433c2c50f8bbf
ip-192-168-3-40:Shopify-Gateway username$ git diff
ip-192-168-3-40:Shopify-Gateway username$

为什么 govendor 不更新我的包裹?

【问题讨论】:

  • “有自然替代品吗?” Go Modules 将是自然的替代品。 Govendor 很可能被放弃了,因为在 Go 1.5(几年前)中添加了 vendoring,并且在 Go 1.11(一年多前)中添加了完整的依赖管理(Go Modules)。
  • 查看这里了解信息:github.com/golang/go/wiki/Modules
  • 这是由govendor itself 回答的。 TLDR; “使用 Go 模块”
  • 你运行mod god init了吗? mod 工具既可以理解旧的 govendor 清单,也可以要求基于特定提交的依赖项。即使你不转换vendor.json,你仍然可以go get特定的提交和版本。

标签: go package-managers govendor


【解决方案1】:

您必须迁移到go modules。 首先,创建一个新模块。通过这些简单的步骤,您将能够初始化一个模块并创建go.mod 文件[https://stackoverflow.com/a/57944766/9361998]

你必须输入:

go mod init YOUR_REPOSITORY_NAME
go clean 
go mod download # wait until dependencies are downloaded
go build #be sure that the code compile
go mod tidy #prune unnecessary dependencies
go get -u ./... #update dependencies

请注意,使用最新命令您将更新 dep 到最新的 MINOR 补丁,请务必将 go.mod 文件更改为最新的 MAJOR 版本

编辑

另一种方法是使用go get -v -u github.com/repository_name/module_name 下载GOPATH 中的模块。通过这种方式,模块将被下载到您的GOPATH

【讨论】:

  • 感谢您的回答。尝试这样做但无法使其工作,请在原始问题中进行编辑。但如果可能的话,我同意这将是最好的解决方案。
  • 谢谢先生!请记住,您可以手动修改go.mod 文件以更改版本。比运行go cleango get -v -u ./...
  • 您缺少 go init,在这种情况下,它将尝试将供应商清单转换为 go.mod。 go clean 不下载任何依赖项。您不应该通过编辑go.mod 来获取新版本,并且您不能通过编辑go.mod 来更新大于1 的主要版本,因为必须在源中更改导入路径。
  • 嗨@JimB,我没有添加go mod init 步骤,而是选择链接如何创建模块的简短描述。谢谢,我想念go mod download
猜你喜欢
  • 1970-01-01
  • 2021-03-07
  • 2021-09-10
  • 2018-03-19
  • 2011-04-01
  • 2018-07-22
  • 1970-01-01
  • 1970-01-01
  • 2012-07-29
相关资源
最近更新 更多