Back to Concepts Roadmap
🟑 Level 1 β€” Fundamentals
Foundation

Basic Syntax

Learn the core rules of Go: semicolon insertion, export visibility (Capitalization), and commenting.

Real-World Analogy (Mental Model)

β€œCapital letters in Go are like VIP badges. If a function or variable starts with a Capital letter, it can leave the room (public). If it starts with lowercase, it stays private in the room.”

Architecture & Memory MapVisual Model
[Inside package mathutil]
  β”œβ”€β”€ CalculateTotal()  ──> Starts with Capital 'C' ──> 🟒 PUBLIC (Exported)
  └── helperFunction()  ──> Starts with Lowercase 'h' ──> πŸ”’ PRIVATE (Unexported)

Key Concepts & Rules To Remember

  • Visibility is determined purely by capitalization: `ExportedName` vs `unexportedName`.
  • No trailing semicolons required β€” the Go lexer inserts them automatically.
  • Go uses `//` for single-line comments and `/* */` for multi-line block comments.
  • Naming convention: use MixedCaps/camelCase (e.g., `userID`, `parseJSON`), never snake_case.
Step-by-Step Code

1. Exported vs Unexported (Public vs Private)

In Go, there are no `public` or `private` keywords. The first letter of any identifier decides its visibility to other packages.

example.goGo 1.24+
package wallet

// Exported (Public): starts with Capital 'B'
// Other packages can do wallet.Balance
var Balance = 1000

// Unexported (Private): starts with lowercase 's'
// Only functions inside package wallet can access this
var secretPin = 1234
Step-by-Step Code

2. Naming Conventions

Go developers follow strict naming rules: keep names concise, use CamelCase, and acronyms should be capitalized together (e.g. `httpServer`, `urlID`, `jsonParser`).

example.goGo 1.24+
// βœ… Good idiomatic Go:
var maxRetryCount = 5
var apiURL = "https://api.example.com"

// ❌ Unidiomatic (Avoid snake_case):
var max_retry_count = 5

Common Beginner Pitfalls & Mistakes

Mistake: Importing a package but not using it.
βœ… Correct Way: Go treats unused imports as compiler errors. Remove unused imports or use `gopls` which cleans them automatically on save.
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.

How do you make a struct field accessible to other packages in Go?

Finished this lesson?

Mark it as complete to track your overall Go mastery.