Zum Inhalt springen
KodeTrail

Camp 1 · Schritt 2 von 12

Hello, World!

Run your first Go program and meet the three-part structure every Go file follows.

10 Min.+50 XPAuf Englisch angezeigt — Übersetzung ist unterwegs

Every Go file follows the same three-beat rhythm. Run it, then read it.

Run

GoCloud-Run

The three beats

  1. package main — every file declares its package; main marks an executable program (vs. a library)
  2. import "fmt" — pull in the format package for printing
  3. func 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 as func 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.