Go go-to guide (original) (raw)
StringsCheat sheet
- Go string handling overview [cheat sheet]
- fmt.Printf formatting tutorial and cheat sheet
- Regexp tutorial and cheat sheet
- Runes and character encoding
- Efficient string concatenation [full guide]
- Escapes and multiline strings
- 3 ways to split a string into a slice
- Convert between byte array/slice and string
- Convert between rune array/slice and string
- Convert between float and string
- Convert between int, int64 and string
- Convert interface to string
- Remove all duplicate whitespace
- 3 ways to trim whitespace (or other characters) from a string
- How to reverse a string by byte or rune
MapsStep-by-step
- Maps explained: create, add, get, delete
- 3 ways to find a key in a map
- Get slices of keys and values from a map
- Sort a map by key or value
Slices and arraysStep-by-step
- Slices/arrays explained: create, index, slice, iterate
- 3 ways to compare slices (arrays)
- How to best clear a slice: empty vs. nil
- 2 ways to delete an element from a slice
- Find element in slice/array with linear or binary search
- Last item in a slice/array
Files
- Read a file (stdin) line by line
- Append text to a file
- Find current working directory
- List all files (recursively) in a directory
- Create a temporary file or directory
Time and date
- Format a time or date [complete guide]
- Time zones
- How to get current timestamp
- Get year, month, day from time
- How to find the day of week
- Days between two dates
- Days in a month
- Measure execution time
Random numbers
- Generate random numbers, characters and slice elements
- Generate a random string (password)
- Generate a unique string (UUID, GUID)
- Shuffle a slice or array
- User-friendly access to crypto/rand
Language basics
- Go beginner’s guide: top 4 resources to get you started
- Packages explained: declare, import, download, document
- Package documentation
- Package initialization and program execution order
Statements
- 4 basic if-else statement patterns
- 5 switch statement patterns
- 5 basic for loop patterns
- 2 patterns for a do-while loop in Go
- 4 basic range loop (for-each) patterns
- Defer a function call (with return value)
- Type assertions and type switches
- Type alias explained
Expressions
- Create, initialize and compare structs
- Pointers explained
- Untyped numeric constants with no limits
- Make slices, maps and channels
- How to append anything (element, slice or string) to a slice
- How to use the copy function
- [Default zero values for all Go types](/golang/default-zero-value/ "Variables declared without an initial value are set to their zero values: 0 or 0.0 for numbers, false for booleans, "" for strings, and nil for interfaces, slices, channels, maps, pointers and functions.")
- Operators: complete list
- Conversions [complete list]
Methods and interfaces
- Methods explained
- Type, value and equality of interfaces
- Named return values [best practice]
- Optional parameters, default parameter values and method overloading
- Variadic functions (...T)
Error handling
- Error handling best practice
- 3 simple ways to create an error
- Panics, stack traces and how to recover [best practice]
Bits and pieces
- Blank identifier (underscore)
- Find the type of an object
- Generics (alternatives and workarounds)
- Pick the right one: int vs. int64
- 3 dots in 4 places
- Redeclaring variables
Standard library
- How to use JSON with Go [best practices] encoding/json
- fmt.Printf formatting tutorial and cheat sheet fmt
- How to use the io.Reader interface io
- How to use the io.Writer interface io
- Create a new image image
- Write log to file (or /dev/null) log
- Hello world HTTP server example net/http
- Regexp tutorial and cheat sheet regexp
- The 3 ways to sort in Go sort
