I learnt that, all .go
files in a directory must name the same package.
Considering below example from github,
fogleman/nes/
nes/
apu.go
cartridge.go
console.go
controller.go
cpu.go
filter.go
ines.go
mapper.go
mapper1.go
mapper2.go
mapper3.go
mapper4.go
mapper7.go
memory.go
palette.go
ppu.go
ui/
util/
.gitignore
LICENSE.md
README.md
main.go
So, All .go
files in directory(../fogleman/nes/nes
) have the package name nes
(same as directory name).
Similarly, all .go
files in directory, ../fogleman/nes/ui
have the package name ui
(same as directory name).
Considering below two files, I have a question,
1)
roms.go
file in directory(../fogleman/nes/util
) has package name main
(different from directory name)
2)
main.go
file in directory(../fogleman/nes
) has package main
(different from directory name).
Question:
Why package name(main
) is different from its directory name?
I believe the author of this repo intended on running roms.go as a separate program for testing. Without putting this file in package main
, this could not be done. If you are in the root project directory:
cd util
go run roms.go path/to/roms/dir