Go语言早期没有包管理工具,社区里go的第三方包托管在各个git托管平台。需要用到包时通过go get 命令工具安装,但这个工具没有版本描述性文件。在go的世界里没有“package.json”这种文件。这个给我们带来直接的影响就是依赖放在外网,而且没有版本约束

而且使用Gopath配置,多个项目时,配置比较繁琐。

目前依赖工具有很多,如:glide、godep等

从1.9版本开始,官方发布依赖工具,用来管理和下载工程依赖的工具。

1
2
3
dep is a prototype dependency management tool for Go. 
It requires Go 1.9 or newer to compile.
dep is safe for production use.

安装

Mac安装

1
brew install dep

linux

1
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh

Windows

1
go get -u github.com/golang/dep/cmd/dep
$GOPATH/bin$PATH

验证

命令行

1
dep

Dep使用

常用命令

1
2
3
dep init
dep ensure
dep ensure -add github.com/pkg/errors
dep init

原理

$GOPATH/pkg/dep/sources

遇到问题

unable to deduce repository and source type for "golang.org/x/***"

持问题,需要翻墙设置代理,安装翻墙工具,查看http代理设置

命令行设置代理

1
2
3
# linux 使用export;window 使用set
export http_proxy=127.0.0.1:1087
export https_proxy=127.0.0.1:1087

Git 也可以设置代理

1
2
git config --global https.proxy http://127.0.0.1:1087
git config --global https.proxy https://127.0.0.1:1087

相关文档

netstat -ano 查看所有连接的PID及端口号