如何使用go get导入特定版本的软件包? [英] How do I import a specific version of a package using go get?

查看:1820
本文介绍了如何使用go get导入特定版本的软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 Node 环境我用来将特定版本的vendor lib安装到项目文件夹中( node_modules )通过告诉 npm package.json 甚至直接从控制台安装该版本的lib,像这样:

  $ npm install express@4.0.0 

然后我用我的项目导入那个版本的软件包:

  var express = require('express'); 

现在,我想用 go 。我怎样才能做到这一点?
是否可以安装特定版本的软件包?如果是这样,使用集中的 $ GOPATH ,我如何导入一个版本而不是另一个版本?

我会做像这样:

  $ go get github.com/wilk/uuid@0.0.1 
$ go get github .com / wilk / uuid @ 0.0.2

但是,如何才能在导入?

解决方案

真的很惊讶没有人提到 gopkg.in



gopkg.in是一种提供封装(重定向)的服务,可让您将版本表达为回购网址,而无需实际创建回购网站。例如gopkg.in/yaml.v1 vs gopkg.in/yaml.v2,即使它们都住在 https://github.com / go-yaml / yaml





如果作者没有遵循正确的版本管理规范(通过在向后兼容性时增加版本号),这并不完美。但它可以与分支和标签一起工作。


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');

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?

I would do something like this:

$ 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?

解决方案

Really surprised nobody has mentioned gopkg.in.

gopkg.in is a service that provides a wrapper (redirect) that lets you express versions as repo urls, without actually creating repos. eg gopkg.in/yaml.v1 vs gopkg.in/yaml.v2, even though they both live at https://github.com/go-yaml/yaml

This isn't perfect if the author is not following proper versioning practices (by incrementing the version number when breaking backwards compatibility), but it does work with branches and tags.

这篇关于如何使用go get导入特定版本的软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆