Tutorial
Go Tutorial
A practical tutorial to get you productive with Go for backend development, CLI tools, and cloud-native applications. Covers fundamentals, concurrency, testing, and the standard library.
Chapters
About this tutorial
A practical tutorial to get you productive with Go.
Who This Is For
- Developers with experience in other languages
- Those wanting to learn Go for backend development, CLI tools, or cloud-native applications
- Anyone looking for a practical, example-driven guide
Contents
Fundamentals
- Introduction - What is Go, installation, first program
- Basics - Variables, types, operators, strings
- Control Flow - If, for, switch, defer
- Functions - Functions, closures, methods
- Collections - Arrays, slices, maps
Object-Oriented Go
- Structs & Methods - Structs, methods, embedding
- Interfaces - Interfaces, polymorphism, type assertions
Core Concepts
- Error Handling - Error patterns, wrapping, custom errors
- Concurrency - Goroutines, channels, sync package
Ecosystem
- Packages & Modules - Project structure, dependencies
- Testing - Unit tests, benchmarks, fuzzing
- Standard Library - Essential stdlib packages
Mastery
- Best Practices - Idioms, patterns, anti-patterns
How to Use This Tutorial
- Read sequentially for a complete learning path
- Jump to specific topics if you need a reference
- Type out the examples - don't just read them
- Build something after each section
Quick Reference
Essential Commands
# Create a new project
mkdir myproject && cd myproject
go mod init github.com/username/myproject
# Run a program
go run main.go
# Build an executable
go build
# Run tests
go test ./...
# Format code
go fmt ./...
# Manage dependencies
go mod tidy
Hello World
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
Common Patterns
// Error handling
result, err := doSomething()
if err != nil {
return fmt.Errorf("doing something: %w", err)
}
// Goroutine with channel
ch := make(chan string)
go func() {
ch <- "result"
}()
result := <-ch
// HTTP handler
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello!")
})
http.ListenAndServe(":8080", nil)
Learning Path Suggestions
Backend Developer (2-3 days)
- Fundamentals (chapters 1-5)
- Structs & Interfaces (6-7)
- Error Handling (8)
- Standard Library (12) - focus on
net/http,encoding/json - Build a REST API
DevOps/CLI Developer (2-3 days)
- Fundamentals (chapters 1-5)
- Error Handling (8)
- Packages & Modules (10)
- Standard Library (12) - focus on
os,flag,exec - Build a CLI tool
Systems Programmer (1 week)
- All fundamentals (1-9)
- Deep dive into Concurrency (9)
- Standard Library (12) - focus on
sync,io,os - Build a concurrent data processor
Additional Resources
- Official Go Documentation
- Go by Example
- Effective Go
- Go Playground - Try Go in the browser
- Go Wiki
Go Version
This tutorial is written for Go 1.21+ and covers features up to Go 1.22.