Go by Example
Go by Example is a hands-on introduction to Go using annotated example programs. It’s designed to help you learn Go through practical, runnable code examples that demonstrate the language’s features and standard library.What is Go by Example?
Go by Example teaches Go via annotated example programs. Each example is a complete, working program that demonstrates a specific concept or feature of the language. The examples include:- Line-by-line code annotations explaining what each part does
- Expected output showing what the program produces
- Additional notes and best practices
Explore by Topic
Basics
Variables, constants, loops, conditionals, arrays, slices, maps, and functions
Methods & Interfaces
Structs, methods, interfaces, generics, and struct embedding
Concurrency
Goroutines, channels, select, worker pools, mutexes, and atomic operations
Standard Library
JSON, XML, HTTP, file I/O, regular expressions, time, and more
How to Use This Site
Each example is structured to maximize learning:- Read the Code - Every example starts with complete, runnable Go code
- Follow the Annotations - Inline comments explain each line and concept
- See the Output - Expected program output is shown after the code
- Try It Yourself - Copy and run the examples on your own machine
All examples are designed to work with modern Go versions. Check the Go release history for the latest version.
What You’ll Learn
Go by Example covers the full spectrum of Go programming:Core Language
- Basic types and control flow
- Functions, closures, and recursion
- Pointers, structs, and methods
- Interfaces and generics
- Error handling patterns
Concurrency
- Goroutines and channels
- Channel buffering and synchronization
- Select statements and timeouts
- Worker pools and rate limiting
- Mutexes and atomic counters
Standard Library
- String manipulation and formatting
- JSON and XML processing
- File and directory operations
- HTTP clients and servers
- Command-line arguments and flags
- Testing and benchmarking
Advanced Topics
- Context for cancellation
- Process spawning and signals
- Regular expressions
- Time handling and parsing
- Custom iterators
Getting Started
Ready to start learning Go? Head over to the Quickstart to install Go and run your first program, or jump straight into the examples starting with Hello World.Quickstart Guide
Install Go and run your first program in minutes