安装(linux下源码安装)
# 注意:需要golang环境
go get -u github.com/golang/dep/cmd/dep
cd github.com/golang/dep/cmd/dep
go build
# 然后生成dep二进制执行文件,把dep放于PATH路径下方便后续操作
# 建立一个demo测试环境
mkdir -p demo/src/app && cd demo/src/app && export GOPATH=`pwd`
# dep 初始化
dep init
# 执行后生成如下文件
tree
# .
# ├── Gopkg.lock # 这个不用管
# ├── Gopkg.toml # 定制三方包规则文件
# └── vendor # 各种三方包文件目录
#
# 1 directory, 2 files
# 打开Gopkg.toml,开始编辑
# 例如,要添加一个三方包:
# required = ["github.com/gorilla/mux"]
# 修改后执行下面命令进行更新,注意,此时需要建一个正常编译的go文件,我们这里建立一个main.go,内容如下:
# package main
# func main() {}
dep ensure
# 查看vendor目录,需要的包已经安装了
tree vender
# vendor/
# └── github.com
# └── gorilla
# ├── context
# │ ├── context.go
# │ ├── context_test.go
# │ ├── doc.go
# │ ├── LICENSE
# │ └── README.md
# └── mux
# ├── bench_test.go
# ├── context_gorilla.go
# ├── context_gorilla_test.go
# ├── context_native.go
# ├── context_native_test.go
# ├── doc.go
# ├── LICENSE
# ├── mux.go
# ├── mux_test.go
# ├── old_test.go
# ├── README.md
# ├── regexp.go
# └── route.go
#
# 4 directories, 18 files
# 通常,我们用下面命令查看状态
dep status
# 执行结果如下
# PROJECT CONSTRAINT VERSION REVISION LATEST PKGS USED
# github.com/gorilla/context v1.1 v1.1 1ea2538 1ea2538 1
# github.com/gorilla/mux v1.6.0 v1.6.0 7f08801 7f08801 1
# 如果我们对三方包有版本要求,比如github.com/gorilla/mux需要1.6.0以下的版本
# 打开Gopkg.toml,添加如下内容:
# [[constraint]]
# name = "github.com/gorilla/mux"
# version = "<1.6.0"
# 然后执行:
dep ensure
# 最终查看状态:
dep status
# PROJECT CONSTRAINT VERSION REVISION LATEST PKGS USED
# github.com/gorilla/context v1.1 v1.1 1ea2538 1ea2538 1
# github.com/gorilla/mux <1.6.0 v1.5.0 24fca30 24fca30 1
# 最终,项目目录结构如下:
tree
# .
# ├── Gopkg.lock
# ├── Gopkg.toml
# ├── main.go
# └── vendor
# └── github.com
# └── gorilla
# ├── context
# │ ├── context.go
# │ ├── context_test.go
# │ ├── doc.go
# │ ├── LICENSE
# │ └── README.md
# └── mux
# ├── bench_test.go
# ├── context_gorilla.go
# ├── context_gorilla_test.go
# ├── context_native.go
# ├── context_native_test.go
# ├── doc.go
# ├── LICENSE
# ├── mux.go
# ├── mux_test.go
# ├── old_test.go
# ├── README.md
# ├── regexp.go
# └── route.go
#
# 5 directories, 21 files
# 详细文档参见:https://github.com/golang/dep/
网友评论