The main package defines an executable Go program. A Go file begins with its package name; when that name is main, the compiler looks there for the special main function, which runs when the program starts. A small executable can keep main.go in the project root, while several binaries commonly use cmd/{binary_name}/main.go. section 2.1.1 section 6.1
Listing 2.1 main.go
package main
import "fmt"
func main() {
fmt.Println("Hello world")
}
A complete main.go example shows the package declaration, import, entry-point function, and executable output together. section 2.1.1
A minimal executable follows this structure:
- Declare package main at the top of the Go file. section 2.1.1
- Define func main() as the program's entry point. section 2.1.1
- Place a single binary's main.go at the project root; organize multiple binaries under cmd/{binary_name}/. section 6.1

