Every Go file starts with package <something>
.
As far as I understand - and this is probably where I am missing some information - there are only two possible values for <something>
: The name of the directory it is in*, or main
. If it is main
, all other files in that directory can only have main
, too. If it is something else, the project is inconsistent/violating convention.
Now if it is the name of the directory, it's redundant, because the same information is, well, in the name of the directory.
If it is main
, it's kind of useless, because as far as I can see there is no way to tell go build
to "please build all main
packages".
* Because, in other words, one directory is one package.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…