今天读了golang官方文档中的module介绍
https://blog.golang.org/using-go-modules
从go1.11之后,Google应该是想把module变成正统包管理器了。在此,我简单的以工程角度探究一下mod。
首先,文档提到:
A module is a collection of Go packages stored in a file tree with a go.mod file at its root. The go.mod file defines the module’s module path, which is also the import path used for the root directory, and its dependency requirements, which are the other modules needed for a successful build.
也就是说,module是go package的集合。它定义了module path,dependencies等等。我们写一个小项目,结构如下:
我们创建一个不在GOPATH目录下的测试项目(官网中提到,GOPATH下的向后兼容,跟之前版本的管理办法一样)。我的go.mod设置的module path跟实际路径不一样,为了测试module path可不可以跟实际路径不同。结果如下:
可以看到,实际path是./hello
,而go.mod