登录
首页 >  Golang >  Go问答

在 labix.org 的 go 模块 mgo 中实施替代方法

来源:stackoverflow

时间:2024-03-04 20:45:30 186浏览 收藏

Golang不知道大家是否熟悉?今天我将给大家介绍《在 labix.org 的 go 模块 mgo 中实施替代方法》,这篇文章主要会讲到等等知识点,如果你在看完本篇文章后,有更好的建议或者发现哪里有问题,希望大家都能积极评论指出,谢谢!希望我们能一起加油进步!

问题内容

使用 go 模块,我想将 labix.org/v2/mgo 替换为 github.com/globalsign/mgo。 http://labix.org/mgo 存储库未维护,已分叉至 https://github.com/globalsign/mgo

  • 我的代码存储在 $gopath 外部的 ~/git/foo 目录中
  • 我使用的是 go1.11
  • 其他 go 模块正在工作(例如 go list -m all 列出其他模块,文件 go.modgo.sum 正在自动更新。请参阅下面的完整文件)

我已在 go.mod 文件中尝试了以下操作:

replace labix.org/v2/mgo => github.com/globalsign/mgo v0.0.0-20181015145952-eeefdecb41b842af6dc652aaea4026e8403e62df

运行 go build 会出现以下错误:

build github.com/foo/bar: cannot find module for path labix.org/v2/mgo

go帮助模块中的文档讨论了伪版本,例如v0.0.0-yyy..,我正在尝试使用它,因为https://github.com/globalsign上的标签/mgo 的形式为 r2018.06.15,而不是 v1.2.3(语义版本控制)。

此外go帮助模块说:

pseudo-versions never need to be typed by hand: the go command will accept
the plain commit hash and translate it into a pseudo-version (or a tagged
version if available) automatically. this conversion is an example of a
module query.

但是,当我在克隆的 github.com/globalsign/mgo (位于 $gopath/src/github.com/globalsign/mgo)中时,我无法计算出生成伪版本的命令。因此我手动生成的伪版本可能是错误的。

完整的 go.mod 文件如下所示:

module github.com/foo/bar                                                                                                                                     

replace labix.org/v2/mgo => github.com/globalsign/mgo v0.0.0-20181015145952-eeefdecb41b842af6dc652aaea4026e8403e62df                                                                          

require (                                                                                                                                                                                     
  github.com/DATA-DOG/godog v0.7.8                                                                                                                                                            
  github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38 // indirect                                                                                                                 
  github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721 // indirect                                                                                                                 
  github.com/alecthomas/repr v0.0.0-20181024024818-d37bc2a10ba1 // indirect
  ...                                                                                                                   
)

解决方案


尝试go edit -replace命令,不要修改原包的行。 这样你不需要事先知道确切的 pseudo version,只需要知道提交哈希 id。

因此,在您的情况下,不要手动修改“labix.org/v2/mgo”的 go.mod require 部分,并运行此命令将您的分支的提交“eeefdec”附加到 labix 版本之上:

$ GO111MODULE="on"  go mod edit -replace=labix.org/v2/mgo=github.com/globalsign/mgo@eeefdec

第一次构建或测试模块后,go 将尝试拉取新的提交,然后为您生成具有正确伪版本的“替换”行。然后你会在 go.mod 的底部看到:

终于介绍完啦!小伙伴们,这篇关于《在 labix.org 的 go 模块 mgo 中实施替代方法》的介绍应该让你收获多多了吧!欢迎大家收藏或分享给更多需要学习的朋友吧~golang学习网公众号也会发布Golang相关知识,快来关注吧!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>