Golang开发Go依赖管理工具dep安装验证实现过程
程序员文章站
2022-03-03 11:00:29
目录go依赖管理工具环境要求目前版本安装验证初始化默认初始化优先从$gopath初始化gopkg.tomlgopkg.lock常用命令dep ensuredep ensure -adddep ensu...
go依赖管理工具
go dependency management tool
环境要求
golang >= 1.9dep
目前版本
dep: version : devel build date : git hash : go version : go1.10 go compiler : gc platform : linux/amd64
latest release
为v0.4.1
安装
go get -u github.com/golang/dep/cmd/dep
若$gopath/bin
不在path
下,则需要将生成的dep
文件从$gopath/bin
移动至$gobian
下
验证
$ 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 prune pruning is now performed automatically by dep ensure. version show the dep version information 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.
初始化
在项目根目录执行初始化命令,dep
在初始化时会分析应用程序所需要的所有依赖包,得出依赖包清单
并生成vendor
目录,gopkg.toml
、gopkg.lock
文件
默认初始化
$ dep init -v
直接从对应网络资源处下载
优先从$gopath初始化
$ dep init -gopath -v
该命令会先从$gopath
查找既有的依赖包,若不存在则从对应网络资源处下载
gopkg.toml
该文件由dep init
生成,包含管理dep
行为的规则声明
required = ["github.com/user/thing/cmd/thing"] ignored = [ "github.com/user/project/pkgx", "bitbucket.org/user/project/pkga/pkgy" ] [metadata] key1 = "value that convey data to other systems" system1-data = "value that is used by a system" system2-data = "value that is used by another system" [[constraint]] # required: the root import path of the project being constrained. name = "github.com/user/project" # recommended: the version constraint to enforce for the project. # note that only one of "branch", "version" or "revision" can be specified. version = "1.0.0" branch = "master" revision = "abc123" # optional: an alternate location (url or import path) for the project's source. source = https://github.com/myfork/package.git # optional: metadata about the constraint or override that could be used by other independent systems [metadata] key1 = "value that convey data to other systems" system1-data = "value that is used by a system" system2-data = "value that is used by another system"
gopkg.lock
该文件由dep ensure
和dep init
生成,包含一个项目依赖关系图的传递完整快照,表示为一系列[[project]]
节
# this file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. [[projects]] branch = "master" name = "github.com/golang/protobuf" packages = [ "jsonpb", "proto", "protoc-gen-go/descriptor", "ptypes", "ptypes/any", "ptypes/duration", "ptypes/struct", "ptypes/timestamp" ] revision = "bbd03ef6da3a115852eaf24c8a1c46aeb39aa175"
常用命令
dep ensure
从项目中的gopkg.toml
和gopkg.lock
中分析关系图,并获取所需的依赖包
用于确保本地的关系图、锁、依赖包清单完全一致
dep ensure -add
# 引入该依赖包的最新版本 dep ensure -add github.com/pkg/foo # 引入具有特定约束(指定版本)的依赖包 dep ensure -add github.com/pkg/foo@^1.0.1
dep ensure -update
将gopkg.lock
中的约定依赖项更新为gopkg.toml
允许的最新版本
以上就是golang开发go依赖管理工具dep安装验证实现过程的详细内容,更多关于golang开发go依赖管理工具dep的资料请关注其它相关文章!