Camp 1 · Step 2 of 12
Hello, World!
Run your first Go program and meet the three-part structure every Go file follows.
10 min+50 XP
Every Go file follows the same three-beat rhythm. Run it, then read it.
Run
GoCloud run
The three beats
package main— every file declares its package;mainmarks an executable program (vs. a library)import "fmt"— pull in the format package for printingfunc main()— execution starts exactly here
Go's opinions, visible already
- No semicolons (the compiler inserts them invisibly)
- Braces required, and the opening
{must sit on the same line asfunc main()— a different placement is a compile error - Unused imports are errors — delete the Println lines above and run:
Go refuses to compile with an unused
"fmt". Dead code never accumulates.
Checkpoint
What does 'package main' signify?
Checkpoint
You import a package but never use it. What happens?
What's next
Packages and main in depth — how Go programs are organized and why capitalization is Go's version of public/private.