Lesson 1. Get ready, get set, Go
Lesson 2. A glorified calculator
Listing 2.1. Hello Mars: mars.go
Listing 2.3. Traveling at the speed of light: lightspeed.go
Listing 2.4. Assignment operators: shortcut.go
Lesson 3. Loops and branches
Listing 3.1. A function that returns a Boolean value: contains.go
Listing 3.2. Comparing numbers: compare.go
Listing 3.4. Leap year determination: leap.go
Listing 3.5. The not operator: torch.go
Listing 3.6. The switch statement: concise-switch.go
Listing 3.7. The switch statement: switch.go
Lesson 4. Variable scope
Listing 4.1. Scoping rules: scope.go
Listing 4.2. A condensed countdown: loop.go
Listing 4.3. Short declaration in a for loop: short-loop.go
Listing 4.4. Short declaration in a if statement: short-if.go
Listing 4.5. Short declaration in a switch statement: short-switch.go
Lesson 6. Real numbers
Listing 6.1. 64-bit vs. 32-bit floating-point: pi.go
Listing 6.2. Declaring a variable without a value: default.go
Listing 6.3. Formatted print for floating-point: third.go
Listing 6.4. Zero padding: third.go
Listing 6.5. Floating-point inaccuracies: float.go
Lesson 7. Whole numbers
Listing 7.1. Inspect a variable’s type: inspect.go
Listing 7.2. Integers wrap around: integers-wrap.go
Listing 7.3. Display the bits: bits.go
Lesson 8. Big numbers
Listing 8.1. Days to Alpha Centauri: alpha.go
Listing 8.2. Days to Andromeda Galaxy: andromeda.go
Lesson 9. Multilingual text
Listing 9.1. Raw string literals: raw.go
Listing 9.2. Multiple-line raw string literals: raw-lines.go
Listing 9.3. String type: raw-type.go
Listing 9.4. rune and byte: rune.go
Listing 9.5. Indexing into a string: index.go
Listing 9.6. Manipulate a single character: caesar.go
Listing 9.7. ROT13 cipher: rot13.go
Lesson 10. Converting between types
Listing 10.1. Mars age: mars-age.go
Listing 10.2. Ariane type conversion: ariane.go
Listing 10.3. Converting rune to string: rune-convert.go
Listing 10.4. Integer to ASCII: itoa.go
Lesson 12. Functions
Lesson 13. Methods
Listing 13.1. A Celsius type: celsius.go
Listing 13.2. A celsius type behaves like a float64: celsius-addition.go
Listing 13.3. Types can’t be mixed
Listing 13.4. Functions with custom types: temperature-types.go
Lesson 14. First-class functions
Listing 14.1. Interchangeable sensor functions: sensor.go
Listing 14.2. A function as a parameter: function-parameter.go
Listing 14.3. Anonymous function: masquerade.go
Listing 14.4. Anonymous function: funcvar.go
Lesson 16. Arrayed in splendor
Listing 16.1. Array of planets: array.go
Listing 16.2. Array of dwarf planets: dwarfs.go
Listing 16.3. A full array of planets: composite.go
Listing 16.4. Looping through an array: array-loop.go
Listing 16.5. Iterating through an array with range: array-range.go
Listing 16.6. Arrays are values: array-value.go
Lesson 17. Slices: windows into arrays
Listing 17.1. Slicing an array: slicing.go
Listing 17.2. Default indices: slicing-default.go
Listing 17.3. Start with a slice: dwarf-slice.go
Lesson 18. A bigger slice
Listing 18.1. More dwarf planets: append.go
Listing 18.2. Len and cap: slice-dump.go
Listing 18.3. append to slice: slice-append.go
Listing 18.4. Capacity after slicing: three-index-slicing.go
Lesson 19. The ever-versatile map
Listing 19.1. Average temperature map: map.go
Listing 19.2. Pointing at the same data: whoops.go
Listing 19.3. Frequency of temperatures: frequency.go
Lesson 21. A little structure
Listing 21.1. Introducing a little structure: struct.go
Listing 21.2. Location type: location.go
Listing 21.3. Composite literal with field-value pairs: struct-literal.go
Listing 21.4. Composite literal with values only: struct-literal.go
Listing 21.5. Printing keys of structures: struct-literal.go
Listing 21.6. Assignment makes a copy: struct-value.go
Listing 21.7. Two slices of floats: slice-struct.go
Listing 21.8. A slice of locations: slice-struct.go
Lesson 22. Go’s got no class
Listing 22.1. The coordinate type: coordinate.go
Listing 22.2. The decimal method: coordinate.go
Lesson 23. Composition and forwarding
Listing 23.1. Without composition: unorganized.go
Listing 23.2. Structs inside of structs: compose.go
Listing 23.3. An average method: average.go
Listing 23.4. Struct embedding: embed.go
Listing 23.5. Embedding other types: sol.go
Listing 23.6. Another method with the same name: collision.go
Lesson 24. Interfaces
Listing 24.1. A set of methods: talk.go
Listing 24.2. Satisfying an interface: talk.go
Listing 24.3. Polymorphism: talk.go
Listing 24.4. A talker type: shout.go
Listing 24.5. Shout what was spoken: shout.go
Listing 24.6. Shouting: shout.go
Listing 24.7. Embedding satisfies interfaces: starship.go
Listing 24.8. Stardate calculation: stardate.go
Listing 24.9. Stardate interface: stardater.go
Listing 24.10. Sol implementation: stardater.go
Lesson 26. A few pointers
Listing 26.1. Address operator: memory.go
Listing 26.2. Dereference operator: memory.go
Listing 26.3. A pointer type: type.go
Listing 26.4. Declaring a pointer: home.go
Listing 26.5. Administrator for NASA: nasa.go
Listing 26.6. Person structure: struct.go
Listing 26.7. Composite literals: struct.go
Listing 26.8. Pointer to an array: superpowers.go
Listing 26.9. Function parameters: birthday.go
Listing 26.10. Function arguments: birthday.go
Listing 26.11. Pointer receiver: method.go
Listing 26.12. Method call with a pointer: method.go
Listing 26.13. Method call without a pointer: method.go
Listing 26.14. Tomorrow is a new day: day.go
Listing 26.15. The levelUp function: interior.go
Listing 26.16. Interior pointers: interior.go
Listing 26.17. Resetting the chessboard: array.go
Listing 26.18. Modifying a slice: slice.go
Lesson 27. Much ado about nil
Listing 27.1. Nil leads to panic: panic.go
Listing 27.2. Guard against panic: nopanic.go
Listing 27.3. Nil receivers: method.go
Listing 27.4. Guard clause: guard.go
Listing 27.5. Function types that are nil: fn.go
Listing 27.6. A default function: sort.go
Listing 27.7. Growing a slice: slice.go
Listing 27.8. Start with nil: mirepoix.go
Listing 27.9. Reading a map: map.go
Listing 27.10. Interfaces can be nil: interface.go
Listing 27.11. Wat?: interface.go
Listing 27.12. Inspecting the Go representation: interface.go
Lesson 28. To err is human
Listing 28.2. Calling proverbs: proverbs.go
Listing 28.3. Writing Go Proverbs: proverbs.go
Listing 28.4. defer cleanup: defer.go
Listing 28.5. Storing error values: writer.go
Listing 28.6. The road to proverbs: writer.go
Listing 28.7. Sudoku grid: sudoku1.go
Listing 28.8. Validate parameters: sudoku1.go
Listing 28.9. Helper function: sudoku1.go
Listing 28.10. Set a digit: sudoku1.go
Listing 28.11. Declare error variables: sudoku2.go
Listing 28.12. Return the error: sudoku2.go
Listing 28.13. Which error in main: sudoku2.go
Listing 28.14. The error interface
Listing 28.15. Custom error type: sudoku3.go
Listing 28.16. Appending errors: sudoku3.go
Lesson 30. Goroutines and concurrency
Listing 30.1. Sleepy gopher: sleepygopher.go
Listing 30.2. Five sleepy gophers: sleepygophers.go
Listing 30.3. Identified gophers: identifiedgophers.go
Listing 30.4. Channeled sleeping gophers: simplechan.go
Listing 30.5. Impatiently waiting for sleepy gophers: select1.go
Listing 30.6. A randomly sleeping gopher: select2.go
Listing 30.7. Source gopher: pipeline1.go
Listing 30.8. Filter gopher: pipeline1.go
Listing 30.9. Print gopher: pipeline1.go
Listing 30.10. Assembly: pipeline1.go
Listing 30.11. Assembly: pipeline2.go
Listing 30.12. Assembly: pipeline2.go
Lesson 31. Concurrent state
Listing 31.1. Locking and unlocking a mutex: mutex.go
Listing 31.2. Page reference map: scrape.go
Listing 31.3. Visit link: scrape.go
Listing 31.4. Number printing worker: printworker.go
Listing 31.5. Position updating worker: positionworker.go
Listing 31.6. RoverDriver type: rover.go
Listing 31.7. Create: rover.go
Listing 31.8. Command type: rover.go
Listing 31.9. RoverDriver worker: rover.go
Appendix Appendix. Solutions