为什么Go中有包声明? [重复]

This question already has an answer here:

Why do we need to put a package declaration in every file in folder to mark the specified .go files as a part of a package?

Instead the directory name itself could be a package name for all files it contains.

So what the ideological point for this decision?

</div>

Instead the directory name itself could be a package name for all files it contains.

Egor, you probably suppose that in one directory go-files only from one package.

You are almost correct if you exclude tests.

Tests are exception from rule "one directory - one package".