TL;DR (Quick Summary)#
- Go Philosophy: Simple, explicit, statically typed, garbage-collected, and blazingly fast compilation.
- Go Modules (
go mod init <name>): The standard dependency management system introduced in Go 1.11+. - Variable Declarations: Explicit (
var x int = 10) vs Short Declaration Operator (x := 10). - Zero Values: Uninitialized variables automatically receive default zero values (
0for numbers,""for strings,falsefor booleans,nilfor pointers/slices/maps).
1. Installing Go & Setting Up Your Workspace#
Let’s begin by installing the Go toolchain and initializing a workspace.
# Ubuntu / Debian Installation
sudo apt update
sudo apt install golang-go -y
# Verify Installation
go versionExpected Terminal Output:
go version go1.22.0 linux/amd64Initializing a Go Module#
Create a new directory and initialize a Go module:
mkdir go-masterclass && cd go-masterclass
go mod init github.com/username/go-masterclassExpected Terminal Output:
go: creating new go.mod: module github.com/username/go-masterclass2. Writing Your First Go Program (main.go)#
In Go, executable programs must belong to package main and contain a main() entrypoint function.
Create main.go:
package main
import "fmt"
func main() {
fmt.Println("Hello, Gophers! Welcome to Go.")
}Run the program directly using go run:
go run main.goExpected Terminal Output:
Hello, Gophers! Welcome to Go.3. Variables, Constants & Type Inference#
Go is strictly and statically typed, but provides short variable declaration syntax (:=) for local scope type inference.
package main
import "fmt"
// Package-level variables MUST use the 'var' keyword
var PackageName string = "Go Masterclass"
func main() {
// 1. Explicit declaration with type
var age int = 25
// 2. Type inference (compiler infers string)
var name = "Rachmat"
// 3. Short variable declaration operator (Local scope only!)
isEngineer := true
// 4. Multiple variable declaration
var (
serverHost = "localhost"
serverPort = 8080
)
// 5. Constants (Cannot be changed after compile time)
const MaxConnections = 100
fmt.Printf("User: %s (Age: %d, Engineer: %t)\n", name, age, isEngineer)
fmt.Printf("Server: %s:%d (Max: %d)\n", serverHost, serverPort, MaxConnections)
}4. Zero Values Table#
In Go, there is no undefined. Uninitialized variables are automatically assigned their type’s Zero Value.
| Go Type | Default Zero Value |
|---|---|
int, float64, byte | 0 / 0.0 |
string | "" (Empty string) |
bool | false |
| Pointers, Slices, Maps, Channels, Interfaces | nil |
package main
import "fmt"
func main() {
var count int
var title string
var active bool
fmt.Printf("count: %d, title: '%s', active: %t\n", count, title, active)
// Output: count: 0, title: '', active: false
}5. Troubleshooting & Common Errors#
Error 1: x declared and not used#
The Cause: Go enforces strict compiler hygiene. If you declare a local variable and never read it, the compiler will refuse to build!
The Fix: Remove the unused variable, or use the blank identifier _ to discard the value.
// 🔴 Compiler Error: unused declared and not used
unused := 100
// 🟢 Good: Discard value using blank identifier
_ = 100Summary & Next Steps#
In this episode:
- We installed the Go toolchain and initialized a
go.modmodule. - We wrote and executed our first
package mainprogram. - We declared variables using
varand:=syntax. - We analyzed Go Zero Values and compiler unused variable errors.
In Episode 2: Control Flow & Loops, we will master if/else branching, switch pattern matching, and Go’s only loop keyword: for!

