我想了解Go语言中包命名规范背后的思想。大多数包都被安装和导入为以下形式:
import "github.com/howeyc/fsnotify"
我知道包名应该是唯一的,但是我不明白为什么要使用网站 github.com
。为什么不直接使用 作者/包名
?例如:
import "howeyc/fsnotify"
那很不可能会发生碰撞。还是采用其他更“短”的策略?这样做是因为它能够与go get
“轻松工作”吗?还是有其他原因?
我想了解Go语言中包命名规范背后的思想。大多数包都被安装和导入为以下形式:
import "github.com/howeyc/fsnotify"
我知道包名应该是唯一的,但是我不明白为什么要使用网站 github.com
。为什么不直接使用 作者/包名
?例如:
import "howeyc/fsnotify"
那很不可能会发生碰撞。还是采用其他更“短”的策略?这样做是因为它能够与go get
“轻松工作”吗?还是有其他原因?
howeyc/fsnotify
。当使用github.com/howeyc/fsnotify
时,它意味着该软件包托管在GitHub上。其他库也可以使用。
原因是这样可以更容易地通过go get
定位和安装依赖项。否则,您将不得不手动满足依赖关系。由于在开源世界中分叉存储库相当普遍,因此您可能有来自同一作者的修改版本。因此有助于区分您的项目所依赖的内容。
Download and install packages and dependencies
Usage:
go get [-d] [-fix] [-u] [build flags] [packages]
Get downloads and installs the packages named by the import paths, along with their dependencies.
When checking out or updating a package, get looks for a branch or tag that matches the locally installed version of Go. The most important rule is that if the local installation is running version "go1", get searches for a branch or tag named "go1". If no such version exists it retrieves the most recent version of the package.
For more about specifying packages, see '
go help packages
'.For more about how 'go get' finds source code to download, see '
go help remote
'.
导入路径支持 go get
命令。指定远程代码库的路径以代码路径开头。运行 go help remote
命令获取详细信息。