What Is Go?
You don’t know Go, yet. Neither do I, not fully anyway. None of us do. But we can all start getting to know Go better.
About the Book
Go programming language study notes turned book.
This book is inspired by ‘You Don’t Know JS Yet’ (YDKJS) book series. YDKJS helped me understand JavaScript under the hood, after more than 8 years writing software in JS.
You Don’t Know Go (YDKGo) book is based on Ultimate Go training, which is an intermediate-level class for engineers with some experience with Go trying to dig deeper into the language.
Table of Contents
Lesson 1: Design Guidelines [ guide]
Language Mechanics
Lesson 2: Language Syntax
- Variables [
guide |
code example |
exercise 1 solution]
- Built-in types
- Zero value concept
- Declare and initialize variables
- Conversion vs casting
- Struct Types [
guide |
exercise 1 solution]
- Declare, create and initialize struct types [ code example]
- Anonymous struct types [ code example]
- Named vs Unnamed types [ code example]
- Pointers [
guide |
exercise 1 solution |
exercise 2 solution]
- Part 1 (Pass by Value) [ code example]
- Part 2 (Sharing Data) [ code example | code example]
- Part 3 (Escape Analysis) [ code example]
- Part 4 (Stack Growth) [ code example]
- Part 5 (Garbage Collection)
- Constants [
guide |
exercise 1 solution]
- Declare and initialize constants [ code example]
- Parallel type system (Kind) [ code example]
- iota [ code example]
- Implicit conversion [ code example]
- Functions [
guide |
exercise 1 solution]
- Return multiple values [ code example]
- Blank identifier [ code example]
- Redeclarations [ code example]
- Anonymous Functions/Closures [ code example]
- Advanced code review
- Recover panics [ code example]
Lesson 3: Data Structures
- Data-Oriented Design
- Design guidelines [ guide]
- Arrays [
guide |
exercise 1 solution]
- Part 1 (Mechanical Sympathy)
- Part 2 (Semantics)
- Declare, initialize and iterate [ code example]
- Different type arrays [ code example]
- Contiguous memory allocations [ code example]
- Range mechanics [ code example]
- Slices [
guide |
exercise 1 solution]
- Part 1
- Declare and Length [ code example]
- Reference Types [ code example]
- Part 2 (Appending Slices) [ code example]
- Part 3 (Taking Slices of Slices) [ code example]
- Part 4 (Slices and References) [ code example]
- Part 5 (Strings and Slices) [ code example]
- Part 6 (Range Mechanics) [ code example]
- Part 7 (Variadic Functions) [ code example]
- Part 1
- Maps [
guide |
exercise 1 solution]
- Declare, write, read, and delete [ code example]
- Absent keys [ code example]
- Map key restrictions [ code example]
- Map literals and range [ code example]
- Sorting maps by key [ code example]
- Taking an element’s address [ code example]
- Maps are Reference Types [ code example]
Lesson 4: Decoupling
- Methods [
guide |
exercise 1 solution]
- Part 1 (Declare and Receiver Behavior) [ code example]
- Part 2 (Value and Pointer Semantics) [ code example]
- Part 3 (Function/Method Variables) [ code example]
- Part 4 (Named Typed Methods) [ code example]
- Part 5 (Function Types) [ code example]
- Interfaces [
guide |
exercise 1 solution]
- Part 1 (Polymorphism) [ code example]
- Part 2
- Method Sets [ code example]
- Address of Value [ code example]
- Part 3 (Storage By Value) [ code example]
- Embedding [
guide |
exercise 1 solution]
- Declaring Fields [ code example]
- Embedding types [ code example]
- Embedded types and interfaces [ code example]
- Outer and inner type interface implementations [ code example]
- Exporting [
guide |
exercise 1 solution]
- Declare and access exported identifiers - Pkg [ code example]
- Declare and access exported identifiers - Main [ code example]
- Declare unexported identifiers and restrictions - Pkg [ code example]
- Declare unexported identifiers and restrictions - Main [ code example]
- Access values of unexported identifiers - Pkg [ code example]
- Access values of unexported identifiers - Main [ code example]
- Unexported struct type fields - Pkg [ code example]
- Unexported struct type fields - Main [ code example]
- Unexported embedded types - Pkg [ code example]
- Unexported embedded types - Main [ code example]
Software Design [ guide]
Lesson 5: Composition [ guide | exercise 1 solution]
- Design Guidelines [ guide]
- Grouping Types
- Grouping By State [ code example]
- Grouping By Behavior [ code example]
- Decoupling
- Struct Composition [ code example]
- Decoupling With Interface [ code example]
- Interface Composition [ code example]
- Decoupling With Interface Composition [ code example]
- Remove Interface Pollution [ code example]
- More Precise API [ code example]
- Conversion and Assertions
- Interface Conversions [ code example]
- Runtime Type Assertions [ code example]
- Behavior Changes [ code example]
- Interface Pollution
- Create Interface Pollution [ code example]
- Remove Interface Pollution [ code example]
- Mocking
- Package To Mock [ code example]
- Client [ code example]
Lesson 6: Error Handling [ guide | exercise solution: 1 | 2]
- Default Error Values [ code example]
- Error Variables [ code example]
- Type As Context [ code example]
- Behavior As Context [ code example]
- Find The Bug [ code example | the reason]
- Wrapping Errors [ code example]
Lesson 7: Packaging
Concurrency [ guide]
Lesson 8: Mechanics - Goroutines [ guide | exercise 1 solution]
- Scheduling in Go
- Language Mechanics [ code example]
- Goroutine Time Slicing [ code example]
- Goroutine and Parallelism [ code example]
Lesson 9: Mechanics - Data Races [ guide | exercise 1 solution]
- Data Race and Race Detection [ code example]
- Synchronization with Atomic Functions [ code example]
- Synchronization with Mutexes [ code example]
- Read/Write Mutex [ code example]
- Map Data Race [ code example]
- Interface-Based Race Condition [ code example]
Lesson 10: Mechanics - Channels [ guide | exercise solution: 1 | 2 | 3 | 4]
- Design Guidelines [ guide]
- Signaling Semantics
- Language Mechanics
- Basic Patterns
- Part 1 (Wait for Task) [ code example]
- Part 2 (Wait for Result) [ code example]
- Part 3 (Wait for Finished) [ code example]
- Pooling Pattern [ code example]
- Fan Out Pattern
- Part 1 [ code example]
- Part 2 [ code example]
- Drop Pattern [ code example]
- Cancellation Pattern [ code example]
Lesson 11: Concurreny Patterns
- Context [
guide |
exercise 1 solution]
- Store / Retrieve context values [ code example]
- WithTimeout [ code example]
- Request/Response Context Timeout [ code example]
- WithCancel [ code example]
- WithDeadline [ code example]
- Failure Detection [ code example]
Testing and Profiling [ guide]
Lesson 12: Testing [ guide]
- Basic Unit Testing [ code example]
- Table Unit Testing [ code example]
- Mocking Server [ code example]
- Testing Internal Endpoints [ code example]
- Sub Tests [ code example]
- Code Coverage
Lesson 13: Benchmarking [ guide | exercise 1 solution]
- Basic Benchmarking [ code example]
- Sub Benchmarks [ code example]
- Validate Benchmarks [ code example]
Lesson 14: Profiling and Tracing
- Profiling Guidelines [ guide]
- Stack Traces [code example: 1 | 2 | 3]
- Micro Level Optimization using Benchmarks [ code example]
- Macro Level Optimization
- Part 1: GODEBUG Tracing [code example: 1 | 2]
- Part 2: Memory Profiling [code example: 1 | 2]
- Part 3: Tooling Changes
- Part 4: CPU Profiling [ code example]
- Execution Tracing [ code example]
Extra Lesson
License
This book contains a variety of content; some developed by Cedric Chee, and some from third-parties. The third-party content is distributed under the license provided by those parties.
The content of this project itself is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License, and the underlying source code used to format and display that content is licensed under the Apache License, Version 2.0.
The Go gopher was designed by Renee French, is licensed under Creative Commons 3.0 Attributions.
Gopher picture by Maria Letta.