安装:
- Mac:
brew install dep
- Linux
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
验证
终端输入dep
➜ ~ dep
Dep is a tool for managing dependencies for Go projects
Usage: "dep [command]"
Commands:
init Set up a new Go project, or migrate an existing one
status Report the status of the project's dependencies
ensure Ensure a dependency is safely vendored in the project
version Show the dep version information
check Check if imports, Gopkg.toml, and Gopkg.lock are in sync
Examples:
dep init set up a new project
dep ensure install the project's dependencies
dep ensure -update update the locked versions of all dependencies
dep ensure -add github.com/pkg/errors add a dependency to the project
Use "dep help [command]" for more information about a command.
使用
项目根目录【xhgblog】下执行 dep init
xhgblog目录下会生成以下文件
├── Gopkg.lock
├── Gopkg.toml
└── vendor
依赖管理
# 添加依赖包
dep ensure -add github.com/go-sql-driver/mysql
# 指定版本
dep ensure -add github.com/go-sql-driver/mysql@=1.4.0
# 同步
dep ensure
# 删除未使用的包
dep piune -v
# 依赖更新
dep ensure -update -v
报错
访问golang.org超时
➜ test git:(master) ✗ dep ensure
The following issues were found in Gopkg.toml:
✗ unable to deduce repository and source type for "golang.org/x/crypto": unable to read metadata: unable to fetch raw metadata: failed HTTP request to URL "http://golang.org/x/crypto?go-get=1": Get http://golang.org/x/crypto?go-get=1: dial tcp 216.239.37.1:80: i/o timeout
ProjectRoot name validation failed
首先使用shadowsocks代理, 但是终端不能用。 需要把socks5 代理转换成 http 代理,然后使用 http_proxy 环境变量, 这样间接实现命令行使用socks5 代理。
解决方案一:
使用polipo 来做代理转换器。
- 安装polipo
brew install polipo
- 代理转换
执行如下命令,开启代理转换器,转换后的代理监听8123端口
polipo socksParentProxy=127.0.0.1:1080 proxyAddress=0.0.0.0
- 通过转换代理执行命令
执行如下命令,就通过8123的http代理访问golang.org
env http_proxy=http://127.0.0.1:8123 https_proxy=http://127.0.0.1:8123 dep ensure -v
解决方案二:
安装Proxifier
参考:
- https://blog.csdn.net/guyan0319/article/details/81588316
- https://studygolang.com/articles/16932
- http://16bing.com/2017/04/23/ss-proxifier
有疑问加站长微信联系(非本文作者)
本文来自:简书
感谢作者:更多精彩内容有,总比没有要好:Go依赖管理工具depfreelanggolang 官方依赖管理工具 dep 使用和持续集成木猫尾巴时间NAV辞典旅游心得:我在旅行途中,你在哪?污大师2018.5.11囧man
查看原文:Go依赖管理工具dep