Main package
The main package is the special Go package that defines an independently executable program, including its entry point.
Learn Go with Pocket-Sized Projects
The main package is the special Go package that defines an executable program's entry point.
- How it is used
- Defines the executable entry point for small Go programs and command-line tools.
- How deep it goes
- Explains package declaration, compiler recognition, function execution, and binary layout without developing package design further.
- Examples
- Uses a Hello World executable and a money-converter command-line tool to demonstrate main package placement.
- What you can do after
- Build it from scratch by declaring package main and implementing func main() in an executable Go project.
Read how Learn Go with Pocket-Sized Projects explains main package →
Go in Action, Second Edition
The main package is the special Go package whose compiled program is intended to be an independently runnable executable.
- How it is used
- Marks the package that begins an independently runnable Go application.
- How deep it goes
- Explains compiler discovery of main and main(), then extends into executable directory organization and package constraints.
- Examples
- Uses a package declaration listing, cmd/myapp/main.go, and a multi-module go-news directory structure.
- What you can do after
- Build an independently runnable executable by combining package main with a main function.
Read how Go in Action, Second Edition explains main package →
Related concepts
- packagekind of · A package is a programming-language namespace and organizational unit that groups related code and may define import, compilation, or access boundaries.
- entry pointhas part · An entry point is a designated starting location or interface through which a program, component, process, or interaction begins.
- const qualifierhas part · A language feature that marks a value, binding, or access path as constant, restricting reassignment or modification according to the language’s rules.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

