Back to Concepts Roadmap
π‘ Level 1 β Fundamentals
Foundation
Hello World
Line-by-line breakdown of your first Go program: packages, standard library imports, and the main entrypoint.
Real-World Analogy (Mental Model)
β`package main` is the front door of your house. When the computer runs your program, it walks right through `package main` and rings the `func main()` doorbell.β
Architecture & Memory MapVisual Model
ββββββββββββββββββββββββββββββββββββββββββ
β package main <-- Entry package β
β import "fmt" <-- Load tools β
β β
β func main() { <-- Entry point β
β fmt.Println("Hello, Gopher!") β
β } β
ββββββββββββββββββββββββββββββββββββββββββKey Concepts & Rules To Remember
- `package main` tells the Go compiler: "This is an executable application, not a library."
- `import "fmt"` imports the Formatted I/O package from the Go Standard Library.
- `func main()` is the starting line where program execution begins.
- Functions are enclosed in curly braces `{}` and the opening brace MUST be on the same line as `func`.
Step-by-Step Code
1. The Code Breakdown
Here is every single line explained for beginners:
example.goGo 1.24+
// 1. Every Go file must belong to a package
package main
// 2. Import packages you need from standard library
import "fmt"
// 3. The main function: execution starts here
func main() {
// Println outputs text with an automatic newline at the end
fmt.Println("Hello, World!")
}Step-by-Step Code
2. Running vs Building
You have two main ways to execute your code: `go run` compiles and runs in memory immediately (great for rapid development), while `go build` saves a standalone binary to disk.
example.goGo 1.24+
# Run immediately:
$ go run main.go
Hello, World!
# Build a binary file:
$ go build main.go
$ ./main
Hello, World!Common Beginner Pitfalls & Mistakes
Mistake: Putting the opening curly brace `{` on a new line (e.g. `func main() \n {`).
β
Correct Way: In Go, the opening brace `{` MUST be on the same line. The compiler automatically inserts semicolons at line endings, so putting `{` on a new line causes a syntax error.
Self Assessment
Knowledge Check
Verify your understanding with these interactive practice questions.
Quizzes
Quick checks for understanding
Multiple-choice with inline explanationsβexpand to see why.
What happens if you name your package `package calculator` instead of `package main`?
Finished this lesson?
Mark it as complete to track your overall Go mastery.