go get 获得 golang.org 的项目
go get 用来动态获取远程代码包的,目前支持的有BitBucket、GitHub、Google Code和Launchpad。这个命令在内部实际上分成了两步操作:第一步是下载源码包,第二步是执行go install。下载源码包的go工具会自动根据不同的域名调用不同的源码工具,对应关系如下:
BitBucket (Mercurial Git)
GitHub (Git)
Google Code Project Hosting (Git, Mercurial, Subversion)
Launchpad (Bazaar)
go get 的参数说明:
-d 只下载不安装
-f 只有在你包含了-u参数的时候才有效,不让-u去验证import中的每一个都已经获取了,这对于本地fork的包特别有用
-fix 在获取源码之后先运行fix,然后再去做其他的事情
-t 同时也下载需要为运行测试所需要的包
-u 强制使用网络去更新包和它的依赖包
-v 显示执行的命令
注意,这里的 –v 参数对我们分析问题很有帮助。
参考:https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/01.3.md
国内由于墙,我们会收到 unrecognized import path 的错误,这时候我们如何通过命令行来执行 go get 呢?
这时我们会获得类似如下错误:
go get -u -v golang.org/x/oauth2
Fetching https://golang.org/x/oauth2?go-get=1
https fetch failed.
import "golang.org/x/oauth2": https fetch: Get https://golang.org/x/oauth2?go-get=1: dial tcp 216.58.221.145:443: i/o timeout
package golang.org/x/oauth2: unrecognized import path "golang.org/x/oauth2"
localhost:~ ghj1976$
如果目录下有以前的版本,则是如下情况:
go get -u -v golang.org/x/oauth2
Fetching https://golang.org/x/oauth2?go-get=1
https fetch failed.
import "golang.org/x/oauth2": https fetch: Get https://golang.org/x/oauth2?go-get=1: dial tcp 216.58.221.145:443: i/o timeout
golang.org/x/oauth2 (download)
Fetching https://golang.org/x/net/context?go-get=1
https fetch failed.
import "golang.org/x/net/context": https fetch: Get https://golang.org/x/net/context?go-get=1: dial tcp 216.58.221.145:443: i/o timeout
golang.org/x/net (download)
Fetching https://golang.org/x/oauth2/internal?go-get=1
https fetch failed.
import "golang.org/x/oauth2/internal": https fetch: Get https://golang.org/x/oauth2/internal?go-get=1: dial tcp 216.58.221.145:443: i/o timeout
golang.org/x/net/context
golang.org/x/oauth2/internal
golang.org/x/oauth2
localhost:~ ghj1976$
这时候我们需要设置代理。代理工具我推荐用 lantern https://github.com/getlantern/lantern
需要注意的是,它的代理地址是: http://127.0.0.1:8787 而不是 http://127.0.0.1:16823/ ,后一个是它的配置网站地址。
以mac为例, 在命令行 Terminal 中设置网络代理,一般方法如下:
root@ed27c545f7af:~# cat ~/proxy.conf
export http_proxy=http://172.17.42.1:8118
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
export rsync_proxy=$http_proxy
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
参考:https://github.com/tools/godep/issues/154
win下 用 set 代理 export ,参考 https://groups.google.com/forum/#!topic/lantern-users-zh/FiywFrEHSHE
删除环境变量用
删除:unset 变量名 参考 http://blog.csdn.net/debug_cpp/article/details/2679991
当前系统上下文的环境设置可以用 env 命令查看。
https://code.google.com/p/go/issues/detail?id=2919
这步代理设置后,我们可以用 wget 命令去试验效果。参考: https://github.com/getlantern/lantern/issues/3341
另外,go get 使用的 git 、mercurial、svn 设置代理的方法请参考:
https://github.com/golang/go/wiki/GoGetProxyConfig
以我们最常用的 git 为例,
在终端设置:
git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080
默认不设置代理:
git config --global --unset http.proxy
git config --global --unset https.proxy
查看已经设置的值:
git config http.proxy
参考: http://blog.csdn.net/dengbin9009/article/details/38058153
配置完成后,以下载 golang.org/x/net 为例,执行的返回值如下:
go get -u -v golang.org/x/net
Fetching https://golang.org/x/net?go-get=1
Parsing meta tags from https://golang.org/x/net?go-get=1 (status code 200)
get "golang.org/x/net": found meta tag main.metaImport{Prefix:"golang.org/x/net", VCS:"git", RepoRoot:"https://go.googlesource.com/net"} at https://golang.org/x/net?go-get=1
golang.org/x/net (download)
package golang.org/x/net: no buildable Go source files in /Users/ghj1976/project/mygocode/src/golang.org/x/net
localhost:text ghj1976$
我们可以看到其实是到 https://go.googlesource.com/text/ 这样的地址去下载源码的。中间涉及到跳转和git下载,所以 要注意, 网络请求的 http_proxy 和 git 的 代理 都需要设置才可以。
go get 获得 golang.org 的项目的更多相关文章
- Golang优秀开源项目汇总, 10大流行Go语言开源项目, golang 开源项目全集(golang/go/wiki/Projects), GitHub上优秀的Go开源项目
Golang优秀开源项目汇总(持续更新...)我把这个汇总放在github上了, 后面更新也会在github上更新. https://github.com/hackstoic/golang-open- ...
- golang多个项目时如何配置GOPATH,使用gb包依赖管理工具,不同项目配置不同的GOPATH的
golang多个项目时如何配置GOPATH,使用gb包依赖管理工具,不同项目配置不同的GOPATH的 1:执行脚本setGoPath.sh#!/bin/bashif [[ $GOPATH =~ .*$ ...
- Golang校招简历项目-简单的分布式缓存
前言 前段时间,校招投了golang岗位,但是没什么好的项目往简历上写,于是参考了许多网上资料,做了一个简单的分布式缓存项目. 现在闲下来了,打算整理下. github项目地址:https://git ...
- github上用golang写的项目
1.moby/moby docker的新马甲 2.kubernetes/kubernetes 分布式容器管理 3.grafana/grafana 一个可视化面板,有漂亮的仪表盘,多种数据来源,适合做系 ...
- Docker部署golang微服务项目
这篇博客是为了记录一下部署步骤. 因为实训需要,我要在服务器上用docker部署我们小组的微服务项目.我们的微服务有Gateway,User,Scene,Device四个部分,分别占用不同的端口,其中 ...
- Golang 开发框架 gin 项目时笔记
1.模板引入时报错: func main() { router := gin.Default() router.LoadHTMLGlob("templates/**/*") rou ...
- [Golang]一些书城项目中出现错误的原因和解决办法(三)
跟着B站尚硅谷的GoWeb教程写书城项目,整理一下自己写的时候出现的错误和解决办法. 错误五:订单管理界面无法显示订单内容. 解决办法:我是直接把 day06 里的 order 文件夹粘贴过来了,or ...
- [Golang]一些书城项目中出现错误的原因和解决办法(二)
跟着B站尚硅谷的GoWeb教程写书城项目,整理一下自己写的时候出现的错误和解决办法. 错误三:数据库的 cart_items 表中 total_count 始终为 0. 原因:更新购物车信息的 Upd ...
- [Golang]一些书城项目中出现错误的原因和解决办法(一)
跟着B站尚硅谷的GoWeb教程写书城项目,整理一下自己写的时候出现的错误和解决办法. 错误一:cartItem中只能加入一种书,SQL语句没有问题,但是购物车中的总金额和总数量正确: 原因:cartI ...
随机推荐
- unity, OnTriggerStay/OnTriggerStay2D not called every fixedUpdate frame
ref: http://answers.unity3d.com/questions/1268607/ontriggerstay2d-do-not-called-every-fixedupdate-un ...
- SourceTree克隆仓库时,总是提示输入密码
1.SourceTree的“工具”-“选项”-“一般”,配置上SSH秘钥: 2.将SSH密钥,配置到GitLab里: 3.仓库的“源路径 / URL”,填写SSH地址:
- HackerRank "The Indian Job"
A sly knapsack problem in disguise! Thanks to https://github.com/bhajunsingh/programming-challanges/ ...
- 8张图带你深入理解Java
1.字符串的不变性 下图展示了如下的代码运行过程: String s = "abcd";s = s.concat("ef"); 备注:String refe ...
- quotas and disk replace on netapp
==================================================================================================== ...
- onNewIntent调用时机
在IntentActivity中重写下列方法:onCreate onStart onRestart onResume onPause onStop onDestroy onNewIntent 一 ...
- 不用删除整个Maven本地库文件夹,Eclipse下直接更新Maven库
- [Android-2A] -仿IOS微信滑动删除_SwipeListview左滑删除例子
https://yunpan.cn/cueUIQkRafQrH (提取码:7ec1) 关于这样类似的例子网上的代码很多,最近发现这个例子里的代码在开发中会遇到一系列的问题.比如ListView的OnI ...
- shell 的语法
SHELL 的语法 n 变量:字符串,数字,环境和参数 n 条件:shell中的布尔值 n 程序控制:if, elif, for, while until, case n 命令列表 n 函数 ...
- suibi11172
http://blog.sina.com.cn/s/blog_12f37f0f00102wi8q.html 七.Python列表操作的函数和方法 列表操作包含以下函数: 1.cmp(list1, li ...