使用这个命令,让官方告诉你modules本质意义

玩了两篇文章,让我们回到原点,试着回答可能是最开始抑或是决定性的问题:

是抛弃Vendor,从此投入Module怀抱么?

客观上,从事物持续发展的眼光看这个问题,回答一定是yes!

那么主观上,怎么让自己信服呢?运行下面的命令,来看Golang官方的解释:

$ go help modules

A module is a collection of related Go packages.
Modules are the unit of source code interchange and versioning.
The go command has direct support for working with modules,
including recording and resolving dependencies on other modules.
Modules replace the old GOPATH-based approach to specifying
which source files are used in a given build.
......

令人惊奇的是,Google竟然把洋洋洒洒近2万个单词组成的文章,塞进了帮助文档里,不知道算不算彩蛋。上面只是摘取了部分文字,如果大家感兴趣,可以到这个gist看全文。

从上面摘取的第一段文字来看Module的设计定位:

  • 在Go项目扮演着包管理员的角色
  • 是源代码互相通信和版本管理的单元
  • 会被go命令行工具强烈支持
  • 基于GOPATH的编译方案将被其取代

因此,官方其实已经下了决心,要大力推广Go Module概念了,大家收拾收拾,可以重新站队了。

PS:官网文档里其实还有这么一段:

If GO111MODULE=off, then the go command never uses the new module support. Instead it looks in vendor directories and GOPATH to find dependencies; we now refer to this as “GOPATH mode.”

所以,让Module Respect Vendor 最简单的方法,就是设置环境变量GO111MODULE为off

 

发表评论

邮箱地址不会被公开。 必填项已用*标注