The entry point for the application is the main
function in the main
package as described in the specification:
A complete program is created by linking a single, unimported package called the main package with all the packages it imports, transitively. The main package must have package name
main
and declare a functionmain
that takes no arguments and returns no value.func main() { … }
Program execution begins by initializing the main package and then invoking the function
main
. When that function invocation returns, the program exits. It does not wait for other (non-main) goroutines to complete.
The language specification does not give special meaning to the name main
outside of this context. The name main
is not a reserved name.
It’s OK to declare a main
function in non-main packages. In such cases, it’s just a function named main
.