如何使用 go get 导入特定版本的包? [英] How do I import a specific version of a package using go get?
问题描述
来自 Node
环境我曾经通过告诉 npm
将特定版本的供应商库安装到项目文件夹 (node_modules
) 中从 package.json
甚至直接从控制台安装该版本的 lib,如下所示:
coming from a Node
environment I used to install a specific version of a vendor lib into the project folder (node_modules
) by telling npm
to install that version of that lib from the package.json
or even directly from the console, like so:
$ npm install express@4.0.0
然后我曾经在我的项目中导入那个版本的包:
Then I used to import that version of that package in my project just with:
var express = require('express');
现在,我想用 go
做同样的事情.我怎样才能做到这一点?是否可以安装特定版本的软件包?如果是这样,使用集中的 $GOPATH
,如何导入一个版本而不是另一个版本?
Now, I want to do the same thing with go
. How can I do that?
Is it possible to install a specific version of a package? If so, using a centralized $GOPATH
, how can I import one version instead of another?
我会做这样的事情:
$ go get github.com/wilk/uuid@0.0.1
$ go get github.com/wilk/uuid@0.0.2
但是,我如何在导入过程中有所作为?
But then, how can I make a difference during the import?
推荐答案
Go 1.11 将有一个称为 go modules 的功能,您可以简单地添加一个版本的依赖项.请按照以下步骤操作:
Go 1.11 will have a feature called go modules and you can simply add a dependency with a version. Follow these steps:
go mod init .
go mod edit -require github.com/wilk/uuid@0.0.1
go get -v -t ./...
go build
go install
这里有关于该主题的更多信息 - https://github.com/golang/go/wiki/模块
Here's more info on that topic - https://github.com/golang/go/wiki/Modules
这篇关于如何使用 go get 导入特定版本的包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!