Go is an open source programming language designed for building scalable, secure and reliable software. Please read the official documentation to learn more.
Go by Example is a hands-on introduction to Go using annotated example programs. Check out the first example or browse the full list below.
Unless stated otherwise, examples here assume the latest major release Go and may use new language features. Try to upgrade to the latest version if something isn't working.
- Hello World
- Values
- Variables
- Constants
- For
- If/Else
- Switch
- Arrays
- Slices
- Maps
- Functions
- Multiple Return Values
- Variadic Functions
- Closures
- Recursion
- Range over Built-in Types
- Pointers
- Strings and Runes
- Structs
- Methods
- Interfaces
- Enums
- Struct Embedding
- Generics
- Range over Iterators
- Errors
- Custom Errors
- Goroutines
- Channels
- Channel Buffering
- Channel Synchronization
- Channel Directions
- Select
- Timeouts
- Non-Blocking Channel Operations
- Closing Channels
- Range over Channels
- Timers
- Tickers
- Worker Pools
- WaitGroups
- Rate Limiting
- Atomic Counters
- Mutexes
- Stateful Goroutines
- Sorting
- Sorting by Functions
- Panic
- Defer
- Recover
- String Functions
- String Formatting
- Text Templates
- Regular Expressions
- JSON
- XML
- Time
- Epoch
- Time Formatting / Parsing
- Random Numbers
- Number Parsing
- URL Parsing
- SHA256 Hashes
- Base64 Encoding
- Reading Files
- Writing Files
- Line Filters
- File Paths
- Directories
- Temporary Files and Directories
- Embed Directive
- Testing and Benchmarking
- Command-Line Arguments
- Command-Line Flags
- Command-Line Subcommands
- Environment Variables
- Logging
- HTTP Client
- HTTP Server
- TCP Server
- Context
- Spawning Processes
- Exec'ing Processes
- Signals
- Exit
by Mark McGranaghan and Eli Bendersky | source | license