iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > GO >Golang开发Go依赖管理工具dep安装验证实现过程是什么
  • 811
分享到

Golang开发Go依赖管理工具dep安装验证实现过程是什么

2023-06-25 15:06:00 811人浏览 独家记忆
摘要

这篇文章主要讲解了“golang开发Go依赖管理工具dep安装验证实现过程是什么”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Golang开发Go依赖管理工具dep安装验证实现过程是什么”吧

这篇文章主要讲解了“golang开发Go依赖管理工具dep安装验证实现过程是什么”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Golang开发Go依赖管理工具dep安装验证实现过程是什么”吧!

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 releasev0.4.1

安装

go get -u GitHub.com/golang/dep/cmd/dep

$GOPATH/bin不在PATH下,则需要将生成的dep文件从$GOPATH/bin移动至$GOBIAN

验证

$ depDep is a tool for managing dependencies for Go projectsUsage: "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 informationExamples:  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.tomlGopkg.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 ensuredep 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.tomlGopkg.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安装验证实现过程是什么这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是编程网,小编将为大家推送更多相关知识点的文章,欢迎关注!

您可能感兴趣的文档:

--结束END--

本文标题: Golang开发Go依赖管理工具dep安装验证实现过程是什么

本文链接: https://www.lsjlt.com/news/305644.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Golang开发Go依赖管理工具dep安装验证实现过程
    目录Go依赖管理工具环境要求目前版本安装验证初始化默认初始化优先从$GOPATH初始化Gopkg.tomlGopkg.lock常用命令dep ensuredep ensure -ad...
    99+
    2024-04-02
  • Golang开发Go依赖管理工具dep安装验证实现过程是什么
    这篇文章主要讲解了“Golang开发Go依赖管理工具dep安装验证实现过程是什么”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Golang开发Go依赖管理工具dep安装验证实现过程是什么”吧...
    99+
    2023-06-25
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作