当前位置:网站首页>golang--module
golang--module
2022-07-22 21:19:00 【IT艺术家-rookie】
什么是go module
Go module实际上只是精准的记录项目的依赖情况,包括每个依赖的精确版本号,仅此而矣。
行末的indirect表示间接依赖
在v1.11中使用go mod init初始化项目时,不填写module名称是没有问题,但在v1.13中,如果项目不在GOPATH目录中,则必须填写module名称。
module: 声明module名称;
module用于指定module的名字,如module github.com/renhongcai/gomodule,那么其他项目引用该module时其import路径需要指定github.com/renhongcai/gomodule。
require: 声明依赖以及其版本号;
require用于指定依赖,如require github.com/google/uuid v1.1.1,该指令相当于告诉go build使用github.com/google/uuid的v1.1.1版本进行编译。
replace: 替换require中声明的依赖,使用另外的依赖及其版本号;
exclude: 禁用指定的依赖;
indirect含义
并不是所有的间接依赖都会出现在 go.mod文件中。
间接依赖出现在go.mod文件的情况,可能符合下面所列场景的一种或多种:
直接依赖未启用 Go module
直接依赖go.mod 文件中缺失部分依赖
依赖包存储
GOPATH模式下,依赖包存储在GOPATH/src,该目录下只保存特定依赖包的一个版本,而在GOMODULE模式下,依赖包存储在GOPATH/pkg/mod,该目录中可以存储特定依赖包的多个版本。
GOPATH/pkg/mod目录下有个cache目录,它用来存储依赖包的缓存,简单说,go命令每次下载新的依赖包都会在该cache目录中保存一份。
export GO111MODULE=off切换到GOPATH模式
export GO111MODULE=on切换到GOMODULE模式。
在GOPATH模式下,go get命令会将依赖包下载到 G O P A T H / s r c / g o o g l e 目录中。该命令等同于在 GOPATH/src/google目录中。 该命令等同于在 GOPATH/src/google目录中。该命令等同于在GOPATH/src/google目录下执行git clone https://github.com/google/uuid.git,也就是$GOPATH/src/google/uuid目录中存储的是完整的仓库。
边栏推荐
- tensorflow2.0稀疏矩阵输入操作
- Application of the latest version of Ontrack easyrecovery computer data recovery software
- Summary in the development process BaseService provides a public access service file for all controllers or services to reduce repeated injection
- 升级poi-tl版本1.12.0与旧版poi(4.1.2)、easyexcel之间的依赖冲突解决
- 使用Flutter与贝塞尔曲线画一个波浪球
- Ftxui basic notes (Hello World)
- 成功解决:error: src refspec master does not match any
- 电子招标采购商城系统:优化传统采购业务,提速企业数字化升级
- Mysql的索引为什么用B+树而不是跳表?
- Talk about repaintboundary in fluent
猜你喜欢

基于ROS的导航框架

LeetCode(剑指 Offer)- 11. 旋转数组的最小数字

记一次线上SQL死锁事故:如何避免死锁?

Wechat campus second-hand book trading applet graduation design finished product (4) opening report
![Leetcode 757 set the intersection size to at least 2[sort greedy] the leetcode path of heroding](/img/69/1bd10b65fe74041720944d0062c19e.png)
Leetcode 757 set the intersection size to at least 2[sort greedy] the leetcode path of heroding

Implementation of remove function

FTXUI基础笔记(hello world)

Report on the progress of writing Chinese experiments by latex

Ftxui basic notes (Hello World)

智能商务的数据分析平台设计与实现
随机推荐
Chapter 2 how to use sourcetree to update code locally
Z-Wave 800: Se firmware upgrade
如何保护 JDBC 应用程序免受 SQL 注入
Here comes the genuine Adobe software! Adobe's only genuine family bucket subscription in the world costs only 0 yuan / year
【无标题】分享一个基于Abp Vnext开发的API网关项目
Redis三种集群方案
记一次线上SQL死锁事故:如何避免死锁?
Is cross modal semantic alignment optimal under comparative learning--- Adaptive sparse attention alignment mechanism IEEE trans MultiMedia
Alibaba Cloud Security Center's best practices for vulnerability repair
关于Redis,是先更新数据库,还是先更新缓存?
FTXUI基础笔记(hello world)
《postgresql指南--内幕探索》第三章查询处理
tensorflow2.0稀疏矩阵输入操作
【刷题记录】18. 四数之和
GNU LD script command language (II)
Problems encountered in punching
Delete the duplicate items in the array (keep the last duplicate elements and ensure the original order of the array)
局域网SDN硬核技术内幕 19 团结一切可以团结的力量
(五)数电——公式化简法
自定义View:悬浮球与加速球