liveBook · Manning

Main package

The main package is the special Go package that defines an independently executable program, including its entry point.

How 2 Manning books explain it

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

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.