我想要一個特定的文件在我的編輯器中出現在我的文件列表頂部,因此我以_
爲前綴。這是它的外觀:搜索以下劃線字符開頭的文件名
mypkg
_func.go
a.go
b.go
我知道如何使用_test
,_unix
Go的文件命名約定等,但是,由於_func
不符合特定架構或者是一個測試的情況下,爲什麼不抱太大希望源文件?
當我導入此包時,此文件中定義的函數不可用。
我想要一個特定的文件在我的編輯器中出現在我的文件列表頂部,因此我以_
爲前綴。這是它的外觀:搜索以下劃線字符開頭的文件名
mypkg
_func.go
a.go
b.go
我知道如何使用_test
,_unix
Go的文件命名約定等,但是,由於_func
不符合特定架構或者是一個測試的情況下,爲什麼不抱太大希望源文件?
當我導入此包時,此文件中定義的函數不可用。
顯然,下劃線權重相同點前綴,在文件的開頭,是工具創建臨時和非衝突的文件明顯被go build
命令忽略。然而,這不是go
工具的決定,而是標準庫中的go/build
包的決定。你可以看到負責的行here。
我的猜測是臨時文件的前綴是下劃線,因此它們被構建工具鏈忽略。
編輯:This comment文件的行爲。我舉:
// 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.
//
,你可以找到在package docs of package go/build
此用戶友好的形式。
我想我記得_whatever
是由類似的方式去處理工具如何點文件(.whatever
)被隱藏在shell中。不幸的是,我找不到任何有關記錄的地方。
因此,如果我的內存服務器正確,您將不得不重新命名源文件,因爲它與Go編譯系統不兼容,在這種情況下,您的意思是將_file.go
視爲某個包的一部分。
此行爲的意圖可能是,允許容易像CGO等