Go directory structure
基本的なGoパッケージは、すべてのコードがプロジェクトのルート・ディレクトリ
1つのモジュール、1つのpackage
テストもルートディレクトリ
同一packageで複数のファイルに分割してもルートディレクトリに置く
多少おおきくなり複雑になったら機能ごとのディレクトリをきってもよい
internalに置いたものは他のプロジェクトからimport不可なのでリファクタリングしやすくなる
code:sh
project-root-directory/
internal/
auth/
auth.go
auth_test.go
hash/
hash.go
hash_test.go
go.mod
modname.go
modname_test.go
複数のインポート可能なパッケージで構成されるプロジェクト
各パッケージには独自のディレクトリがあり、階層的に構造化される
通常、export用packageを持たない
サーバーは通常、自己完結するバイナリになるので、サーバーのロジックを実装するGoパッケージは内部ディレクトリに置く Go 以外のファイルを含むディレクトリがたくさんあるはずなので、すべてのを cmd ディレクトリにまとめる
code:sh
project-root-directory/
go.mod
internal/
auth/
...
metrics/
...
model/
...
cmd/
api-server/
main.go
metrics-analyzer/
main.go
...
... the project's other directories with non-Go code