2013-02-12 31 views
6

特定のファイルをエディタのファイルリストの一番上に表示したいので、接頭辞は_です。これは、それがどのように見えるかです:_funcは特定のアーキテクチャと一致するか、テストケースではありませんので、アンダースコア文字で始まるファイル名を移動する

mypkg 
    _func.go 
    a.go 
    b.go 

私は_testを使用して行くのファイル命名規則、_unixなどについて知るには、しかし、なぜそれがソースとしてカウントされません。ファイル?

このパッケージをインポートすると、このファイルに定義されている機能は使用できません。

答えて

8

どうやら、ファイルの先頭にアンダーウエイトドットプレフィックスと同じにしてあるようなツールのために一時的と競合しないファイルを作成する簡単な可能にするために、おそらくです明示的に無視されます(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でユーザーフレンドリーな形でこれを見つけることができます。

3

_whateverは、ドットファイル(.whatever)がシェル内に隠れているのと同様の方法でgoツールで処理されることを思い出しています。残念ながら、どこに文書化されているのかわかりません。

私のメモリサーバが正しくあれば、そのようなファイルがあるパッケージの一部と見なされることを意味する場合、Goビルドシステムと互換性がないので、ソースファイルの名前を変更する必要があります。

この動作の意図は、CGOなど