我想要一个特定的文件出现在我的编辑器文件列表的顶部,所以我用它作为前缀_
.这是它的样子:
mypkg
_func.go
a.go
b.go
Run Code Online (Sandbox Code Playgroud)
我知道围棋的文件中使用的命名约定_test
,_unix
等等,但是,因为_func
不符合特定架构或者是一个测试的情况下,为什么不指望他的源文件?
导入此包时,此文件中定义的函数不可用.
nem*_*emo 10
显然,下划线的权重与文件开头的点前缀相同,并且go build
命令明显忽略.然而,这不是go
工具的决定,而是go/build
标准库中的包的决定.你可以在这里看到负责任的一行.
我的猜测是临时文件以下划线为前缀,因此构建工具链会忽略它们.
编辑:此评论记录了该行为.我引用:
// Import returns details about the Go package named by the import path,
// interpreting local import paths relative to the srcDir directory.
// If the path is a local import path naming a package that can be imported
// using a standard import path, the returned package will set p.ImportPath
// to that path.
//
// In the directory containing the package, .go, .c, .h, and .s files are
// considered part of the package except for:
//
// - .go files in package documentation
// - files starting with _ or . (likely editor temporary files)
// - files with build constraints not satisfied by the context
//
// If an error occurs, Import returns a non-nil error and a non-nil
// *Package containing partial information.
//
Run Code Online (Sandbox Code Playgroud)
您可以在软件包docs of package中go/build
以用户友好的形式找到它.