Go Mastery
Master Go from syntax to concurrency, generics, and production services. 16 phases covering channels, goroutines, testing, and building performant backend systems.
Your Progress
Complete all 16 phases to master this track
Master Go from syntax to concurrency, generics, and production services. 16 phases covering channels, goroutines, testing, and building performant backend systems.
Phase 1: Environment Setup and First Programs
Install the Go toolchain, run your first compiled program, and learn the formatting habits that define idiomatic code.
Installing the Go Toolchain
Set up go on your PATH and verify the installation with version and environment checks.
Your First Go Program
Write a main package, then run and compile it with go run and go build.
Comments and Doc Comments
Annotate source with line and block comments and write doc comments that surface in godoc.
Variables and Constants
Declare values with var and const, use short declaration, and understand zero values.
Formatting and Inspection Tools
Keep code idiomatic with gofmt, read API docs with go doc, and catch mistakes with go vet.
Phase 2: Types, Operators, and Control Flow
Write clear control flow using Go operators, explicit conversions, if, switch, and its single loop keyword.
Operators and Expressions
Combine values with arithmetic, comparison, logical, and short-circuit operators.
Explicit Type Conversions
Convert between numeric types, strings, bytes, and runes without implicit coercion.
Conditionals with if and else
Branch on boolean conditions using init statements and early returns.
switch Statements
Dispatch on values with single-evaluation switch and deliberate fallthrough.
Loops with for
Use Go's only loop keyword in its three-clause, condition-only, and endless forms.
Phase 3: Functions, Defers, and Error Handling
Define functions with multiple returns, defer cleanup reliably, and handle errors with the error interface.
Function Declarations and Multiple Returns
Declare functions with named parameters, multiple results, and variadic arguments.
The error Interface and Error Messages
Return, wrap, and inspect errors with errors.Is and errors.As.
Anonymous Functions and Closures
Create function values inline and capture surrounding variables by reference.
defer and the Deferred Call Stack
Schedule cleanup that runs in last-in-first-out order when a function exits.
panic, recover, and When to Fail
Trigger and intercept runtime failures while keeping libraries error-oriented.
Phase 4: Structs, Methods, and Interfaces
Model data with structs and methods, then define behavior through implicitly satisfied interfaces.
Defining Structs and Literals
Group fields into structs, build literals, and control field visibility.
Methods with Receivers
Attach functions to types and choose between value and pointer receivers.
Interfaces and Implicit Satisfaction
Define method sets that types satisfy automatically without declaring implements.
Type Assertions and Type Switches
Extract concrete values from interface values safely with comma-ok assertions.
Embedding and Composition
Promote fields and methods with embedding instead of class-style inheritance.
Phase 5: Arrays, Slices, Maps, and Iteration
Manipulate arrays, slices, maps, and text iteration while understanding how they share backing memory.
Fixed-Size Arrays
Work with arrays whose length is part of their type and copied on assignment.
Slice Basics and the Slice Header
Create slices with literals and make while understanding pointer, length, and capacity.
Maps: Insert, Lookup, and Delete
Use map literals, comma-ok lookups, delete, and range with randomized order.
append, copy, and Slice Aliasing
Handle capacity growth, copying, and the aliasing traps of shared backing arrays.
Iterating Strings, Bytes, and Runes
Decode UTF-8 text correctly with range loops and rune conversions.
Phase 6: Pointers, Allocation, and Memory Semantics
Use pointers safely, choose between new and make, and design types whose zero values are ready to use.
Addresses and Pointers
Take addresses with ampersand, declare pointer types, and dereference values.
new, make, and Choosing Allocation
Allocate zeroed values with new and initialized composites with make.
Pointers as Function Parameters
Pass references to avoid copies while keeping mutation explicit at call sites.
Value Semantics and Copies
Predict what assignment and method calls copy before debugging aliasing bugs.
Nil Checks and Zero-Value Design
Handle nil receivers and empty collections without defensive boilerplate.
Phase 7: Packages, Modules, and Project Layout
Organize code into packages, manage dependencies with modules, and structure multi-module repositories.
Packages and Exported Identifiers
Group files into packages and control visibility with capitalization and internal.
Imports, goimports, and go mod tidy
Organize import blocks and keep module requirements in sync with source files.
go.mod and Semantic Versioning
Declare module requirements, verify go.sum hashes, and version major releases.
Import Cycles and Package Design
Break circular dependencies by extracting shared types and inverting interfaces.
Multi-Module Workspaces with go.work
Build several local modules together without publishing or using replace directives.
Phase 8: Goroutines and Shared-State Concurrency
Launch goroutines, coordinate them with WaitGroup and mutexes, and detect data races with tooling.
Starting Goroutines
Run functions concurrently with the go keyword and understand process lifetime.
Coordinating with sync.WaitGroup
Wait for a collection of goroutines to finish without sleeping or polling.
The Race Detector
Build with -race to surface conflicting memory accesses and their stack traces.
Mutexes, RWMutex, and Atomics
Guard shared state with locks and use atomics for single-word counters.
Scheduling and the Happens-Before Relation
Reason about goroutine migration and which operations establish memory visibility.
Phase 9: Channels, Select, and Channel Patterns
Communicate between goroutines with buffered and unbuffered channels, closes, and select statements.
Channel Fundamentals
Send and receive values over unbuffered channels with directional operators.
Buffered Channels
Decouple producers and consumers with a FIFO buffer of fixed capacity.
Closing Channels and Ranging Over Them
Signal completion with close and terminate receivers using the comma-ok form.
select and Non-Blocking Communication
Wait on multiple channel operations, add defaults, and build timeouts.
Directional Channels and Iteration
Restrict APIs with directional channel types and disable select cases with nil.
Phase 10: Concurrency Patterns and Context
Build worker pools, fan-out pipelines, and cancellable operations using context and errorgroup.
Worker Pools
Bound concurrency with a fixed set of goroutines consuming a shared jobs channel.
Fan-Out and Fan-In
Spread work across parallel stages and merge their outputs into one stream.
Parallel Work with errgroup
Run related goroutines under one error and optional concurrency limit.
Cancellation with context
Propagate cancel signals through derived contexts and react on the Done channel.
Timeouts, Deadlines, and Values
Bound work with deadlines and attach request-scoped metadata to contexts.
Finding and Preventing Goroutine Leaks
Diagnose goroutines that block forever and give every worker a shutdown path.
Phase 11: Testing, Coverage, and Benchmarks
Write table-driven tests, measure coverage, benchmark hot paths, and fuzz parsers for hidden bugs.
Unit Tests with the testing Package
Write Test functions with subtests and fail assertions with T methods.
Table-Driven Tests
Organize many input and expected-output cases into one extensible test.
Coverage and Benchmarks
Measure executed statement percentages and allocation counts with testing.B.
Test Doubles with Interfaces
Substitute fakes and stubs for slow dependencies, including in-process HTTP servers.
Fuzzing with go test -fuzz
Generate random inputs against invariants and store crashers as regression corpus.
Phase 12: Generics and the Standard Library
Write generic functions and types while using standard library packages that replace hand-rolled helpers.
strings, fmt, and strconv
Manipulate text, format output, and convert primitives with focused stdlib packages.
Time, Durations, and Tickers
Measure elapsed time, schedule timers, and stop tickers to release resources.
Generic Functions and Type Parameters
Write one function body that works for every type satisfying its constraints.
Constraints and Generic Collections
Restrict type parameters and use the slices, maps, and cmp packages.
Generic Types and Design Limits
Define generic structs and understand instantiation and constraint boundaries.
Phase 13: HTTP Services, JSON, and Middleware
Serve JSON APIs over net/http with middleware, timeouts, and handler tests using httptest.
Building an HTTP Server
Route requests with ServeMux patterns and start the standard library server.
Reading Requests in Handlers
Parse method, path values, query strings, headers, and request bodies correctly.
JSON Encoding and Decoding
Marshal structs with tags and decode request streams without extra buffering.
Middleware and Handler Chaining
Wrap handlers with logging, recovery, and authentication layers that compose.
HTTP Clients, Timeouts, and Retries
Configure client timeouts, cancellation, and backoff for outbound calls.
Testing Handlers with httptest
Exercise handlers in process and start throwaway servers for client tests.
Phase 14: Databases, SQL, and Data Access
Access SQL databases safely with parameterized queries, transactions, migrations, and pool tuning.
database/sql Basics
Open connections, query rows, and scan results with the standard sql package.
Parameterized Queries and Injection Defense
Bind user input as parameters and allow-list any identifiers you must interpolate.
Transactions and Atomic Updates
Group queries into a transaction with commit, rollback, and retry semantics.
Schema Migrations
Version schema changes with ordered SQL files applied across environments.
Connection Pool Tuning
Set open, idle, and lifetime limits so the pool matches database capacity.
Phase 15: CLI Tools, Logging, and Profiling
Ship command-line tools with flags and embedded assets, then diagnose performance with pprof.
Command-Line Flags with the flag Package
Parse typed flags, subcommands, and positional arguments for CLI programs.
Files, Buffers, and Paths
Read and write files with buffered scanners and OS-correct path handling.
Embedding Assets with go:embed
Inline static files into the binary at compile time for single-artifact deploys.
Structured Logging with log/slog
Emit key-value log records as text or JSON with leveled filtering.
CPU and Runtime Profiling with pprof
Capture CPU, heap, and goroutine profiles and read them with go tool pprof.
Heap Analysis and Escape Optimization
Find forced heap allocations with compiler diagnostics and benchmem output.
Phase 16: Production Patterns and Interview Prep
Harden a service for production with graceful shutdown, observability, containers, and interview drills.
Configuration and Secrets Handling
Load validated environment-based configuration without committing secrets.
Idiomatic API and Package Design
Shape constructors, options, and interface boundaries for ergonomic packages.
Graceful Shutdown and Connection Drain
Handle termination signals and drain in-flight requests before exiting.
Metrics, Logs, and Traces
Instrument services with request metrics, correlated logs, and health endpoints.
Containerizing Go Services
Build static binaries and copy them into minimal multi-stage images.
Concurrency Interview Problems
Practice the classic pool, rate limiter, pipeline, and leak-debugging questions.