Go
Language basics
Statements
- Package initialization and program execution order
- For loops explained
- Range loops (for each loops) explained
- do-while loop
- Switch statement
- Defer statement
- Type assertions and type switches
- Type alias
- Where is the ternary conditional operator?
Expressions
- Untyped numeric constants with no limits
- Structs explained
- Slices explained
- Maps explained
- Make slices, maps and channels
- Append function explained
- Copy function explained
- Default value of struct, string, slice, map
- Operator precedence
- Find the type of an object
- Where is the ternary conditional operator?
Methods and interfaces
- Methods explained
- Interfaces explained
- The empty interface
- Named return values
- Optional parameters and method overloading
- Variadic functions (...T)
Error handling
Bits and pieces
- Blank identifier (underscore)
- Generics (alternatives and workarounds)
- iota
- int vs. int64
- Pointers explained
- Three dots (ellipsis) notation
Standard library
- JSON by example
- Print with fmt cheat sheet
- The io.Reader interface
- The io.Writer interface
- Write log to file
- Disable logging
- HTTP server example
- Regular expressions
- How to sort in Go
- Binary search
Tricks of the trade
- Access environment variables
- Bitmasks and flags
- Check if a number is prime
- Command-line arguments
- Compute absolute values
- Compute min and max
- Enumeration (enum) with string representation
- Find build version
- Format byte size to human readable format
- Generate all permutations of a slice or string
- Hash checksums
- Implement a FIFO queue
- Implement a stack (LIFO)
- Iterator pattern
- Round float to 2 decimal places
- Round float to integer value
- Table-driven unit tests
- Top 3 Quicksort optimizations
- What’s the maximum value of an int?
- Write a command-line (CLI) application
- Library package example
- Opening brace on separate line
- How to sort a custom type in Go
- Packages explained
- Package documentation
- Redeclaring variables
- Variable declaration outside of function body
- Unused imports
- Unused local variables
Cheat sheets
- String handling cheat sheet
- Print with fmt cheat sheet
- Format a time or date
- Conversions
- Regular expressions
- Operator precedence
- Bitwise operators cheat sheet
- Operators
Regular Expressions
- Find all substrings matching a regexp
- Find first substring matching a regexp
- Find the location of a regexp substring match
- Replace all substrings matching a regexp
- Split a string using regexp delimiter
- Remove duplicate whitespace from a string
- Repeat string
- Reverse a UTF-8 encoded string
Tutorials
Gotchas
- Why can't I add elements to my map?
- What's a nil pointer dereference?
- Multiple values in single value context?
- Why doesn't this function change my array?
- Two variables with the same name?
- Extra comma in slice literal
- Why can't I update my string?
- Why aren't the characters concatenated?
- What happened to ABBA?
- What happened to my copy?
- Why doesn't append work every time?
- Why can't I print large numbers? (constant overflows int)
- Why doesn't increment (++) and decrement (--) work?
- Why is my computation wrong?
- Why does Go and Pythagoras disagree?
- Why doesn't this loop end?
- Numbers that start with zero
- What's wrong with the remainder (modulo) operator?
- Why can't I multiply a time.Duration with an integer?
- Why is this index out of range?
- Unexpected values in range loop
- Can't change entries in range loop
- Iteration variable doesn't see change in range loop
- Iteration variables and closures
- Why is the JSON output empty?
- Why is nil not equal to nil?
Concurrency
- Goroutines explained
- Channels explained
- Select explained
- Close a channel
- Data races explained
- Detect data races
- Deadlock
- Wait for goroutines
- Broadcast a signal on a channel
- Stop a goroutine
- Make a goroutine block or sleep forever
- Timer and Ticker explained
- Mutual exclusion lock (mutex)
- Efficient parallel computation
Object-oriented programming
- Inheritance and object-oriented programming
- Methods explained
- Constructors
- Public vs. private
- Pointer vs. value receiver
- Access private fields using reflection
Functional programming
Strings
- Print with fmt cheat sheet
- What is a rune?
- Build and concatenate strings efficiently
- String comparison
- Convert string to byte slice (array)
- Convert string to int
- Convert string to int64
- Percent sign in fmt format
- Convert string to rune slice (array)
- Multiline strings
- String handling cheat sheet
- Append string to byte slice
- Format a string without printing it
- How to split a string into a slice
- How to trim leading and trailing whitespace from a string
- Convert interface to string
Slices
- Slices explained
- Clear a slice
- Compare slices (arrays)
- Concatenate slices
- Delete an element from a slice
- Find an element in a slice
- Last item in slice
- Empty slice vs. nil slice
- Pass a slice to a variadic function
Maps
- Maps explained
- Check if a map contains a key
- Check if a map is empty
- Count elements in a map
- Get slices of keys and values from a map
- Sort a map by key or value
- How to implement a set
Files
- Read a file line by line
- Read a whole file into a string (byte slice)
- Read from stdin
- Append text to a file
- Delete a file or directory
- Check if a file or directory exists
- Current working directory
- List all files and folders in a directory
- Visit all files and folders in a directory tree
- Create a temporary file or directory
Time and date
- Current time
- Format a time or date
- Time zones
- Measure execution time
- Get year, month, day from time
- Day of week
- Days between two dates
- Days in a month