Go依赖管理工具dep

安装:

brew install dep
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 来做代理转换器。

  1. 安装polipo
brew install polipo
  1. 代理转换

    执行如下命令,开启代理转换器,转换后的代理监听8123端口

polipo socksParentProxy=127.0.0.1:1080 proxyAddress=0.0.0.0
  1. 通过转换代理执行命令

    执行如下命令,就通过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

参考:

我来评几句
登录后评论

已发表评论数()

相关站点

热门文章