Concept Flow - main package and main function
Start program
Find package main?
Yes
Find func main()?
Yes
Execute func main()
Program ends
The Go program starts by looking for the main package and then runs the main function inside it.
package main import "fmt" func main() { fmt.Println("Hello, Go!") }
| Step | Action | Evaluation | Output |
|---|---|---|---|
| 1 | Start program | Look for package main | |
| 2 | Found package main | Look for func main() | |
| 3 | Found func main() | Prepare to execute main | |
| 4 | Execute fmt.Println("Hello, Go!") | Print string to console | Hello, Go! |
| 5 | End of func main() | Program finishes |
| Variable | Start | After Step 4 | Final |
|---|---|---|---|
| No variables | - | - | - |
package main is required to create an executable program in Go. func main() is the entry point where execution starts. The program runs by executing main function inside main package. Without package main or func main(), the program will not run. Use fmt.Println inside main to print output.