Multiple files in package main

Is it acceptable to have multiple files in package main?

Is it not a recommended practice and, if so, why?

Yes, absolutely ok. It is even acceptable to have subpackages in a package main for specific functionality if that proves necessary

1 Like

Strictly speaking there are no subpackages in Go.

For applications that are composed of multiple packages idiomatic directory structure usually looks like:

root/cmd/app (package main)

Check and for examples.

1 Like

You can have as many files as you want in a Go package. The only special thing about main package is that it will be compiled as executable binary, not .a file.

You can have n-number of files in any package like ‘main’, main is also a package in addition to it, its serves as entry point for binary execution i.e binary files execution starts from main.main(). i.e main package and main method.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.