🐳 Go — Learn From Zero
Playground: Go Playground — click, type, run.
What is Go?
Go (Golang) is a fast, statically-typed language by Google. Built for concurrency and cloud infrastructure.
- Cloud services & microservices
- DevOps tooling (Docker, Kubernetes)
- High-performance APIs
- CLI tools
Run Online — No Install
Use the playground links above.
🟢 Beginner — Core Basics
Your First Program
go
package main
import "fmt"
func main() {
fmt.Println("Hello, world!")
}Every program has package main.
Variables & Types
go
var age int = 36
height := 1.78
name := "Ada"
isStudent := trueUse := for short declaration.
If / Else
go
if age := 18; age >= 18 {
fmt.Println("Vote")
} else {
fmt.Println("Too young")
}If can include an init statement.
Loops
go
for i := 0; i < 5; i++ {
fmt.Println(i)
}Go has only for loops.
Functions
go
func add(a int, b int) int {
return a + b
}Types come after names.
Slices & Maps
go
fruits := []string{"apple", "banana"}
fruits = append(fruits, "cherry")
m := map[string]int{"Ada": 36}Slices are dynamic; maps are built-in.
🟡 Intermediate — Building Real Programs
Structs
go
type Person struct {
Name string
Age int
}
p := Person{"Ada", 36}Group fields in structs.
Methods
go
func (p Person) Greet() string {
return "Hi " + p.Name
}Methods have a receiver.
Interfaces
go
type Stringer interface { String() string }
// satisfied implicitlyDuck typing via interfaces.
Error Handling
go
f, err := os.Open("a.txt")
if err != nil {
log.Fatal(err)
}Errors are values, checked explicitly.
Packages
go
import (
"fmt"
"os"
)Group imports in parentheses.
🔴 Advanced — Pro Concepts
Goroutines
go
go func() {
fmt.Println("async")
}()Lightweight threads via go.
Channels
go
ch := make(chan int)
go func() { ch <- 1 }()
fmt.Println(<-ch)Communicate via channels.
Sync & Mutex
go
var mu sync.Mutex
mu.Lock()
// critical section
mu.Unlock()Protect shared state.
Generics (Go 1.18+)
go
func Map[T any](s []T, f func(T) T) []T { return s }Type parameters with any.
What's Next?
- Build a tiny project: Calculator, To-Do App, Weather Widget
- Read the official docs and a good book
- Solve Exercism exercises
- Join a community & share your code
Practice daily for 20 minutes. Consistency > intensity.