liveBook · Manning

What you will learn in Go in Action, Second Edition

by Joel Holmes, Andrew Walker with William Kennedy

Chapter by chapter

Chapter 1: Go is the solution

The introduction previews the problems Go was designed to solve and the design choices the chapter will explain.

1.1 The problems Go was built to solve · 1.2 Fast compilation and type safety · 1.2.1 Development speed · 1.2.2 Type safety · 1.3 Efficient execution · 1.4 Concurrency built in · 1.4.1 Goroutines · 1.4.2 Channels and context · 1.4.3 A request’s life cycle · 1.5 Simplicity by design · 1.6 World-class tooling · 1.7 What this book covers · 1.8 Summary

What you learn in chapter 1 →

Chapter 2: Diving into Go

The chapter introduces a hands-on Go project that uses a real-world-style utility to teach language fundamentals and introduce Go’s tooling.

2.1 Goal: A program to count words · 2.2 What you need first · 2.2.1 A code editor · 2.2.2 Git · 2.2.3 The Go toolchain · 2.2.4 Terminal access · 2.3 Creating your project root · 2.3.1 Creating a directory · 2.3.2 Initializing the project module · 2.4 The first iteration: Counting spaces · 2.4.1 Creating main.go · 2.4.2 Building the program with go build · 2.4.3 Running the program with go run · 2.4.4 Formatting your code with gofmt · 2.4.5 Package declarations · 2.4.6 Import declarations · 2.4.7 Blocks and scope · 2.4.8 Variable declaration · 2.4.9 Comments · 2.4.10 Basic for loops · 2.4.11 Calling functions in other packages · 2.5 A better way to split the string · 2.5.1 Introducing package strings · 2.5.2 Using go doc to view package documentation · 2.5.3 Multiple imports in an import directive · 2.5.4 Slices and len · 2.6 Reading from a file · 2.6.1 Using the os package to interact with the filesystem · 2.6.2 Multiple return values · 2.6.3 Basic error handling and the log package · 2.6.4 Counting the words in the loaded file · 2.6.5 Running the program on a file · 2.7 Specifying the file · 2.7.1 Getting program arguments from os.Args · 2.7.2 Avoiding a panic by using len · 2.7.3 Running your program with arguments · 2.8 A more efficient method · 2.8.1 Using go doc to learn more about types · 2.8.2 Files and I/O interfaces · 2.8.3 Integrating the scanner loop · 2.8.4 Function types for modifying behavior · 2.9 Reading multiple files · 2.10 Summary

What you learn in chapter 2 →

Chapter 3: Primitive types and operators

The chapter introduces Go’s built-in types as fundamental building blocks and previews the types and operations it will cover.

3.1 Integer types · 3.1.1 Choosing an integer type · 3.2 Floating-point number types · 3.2.1 Special floating-point values · 3.2.2 Choosing a floating-point type · 3.3 Complex number types · 3.4 Mathematical operators · 3.5 The bool type · 3.5.1 Boolean functions · 3.6 Struct types · 3.6.1 Structs as types · 3.7 Pointer types · 3.7.1 Dereferencing pointers · 3.7.2 Creating pointers with new and literals · 3.8 The string type · 3.8.1 Interpreted strings · 3.8.2 Raw string values · 3.8.3 String operations · 3.8.4 len() and Unicode characters · 3.8.5 Iterating Unicode strings using a range loop · 3.8.6 The rune type · 3.8.7 Converting a string to a slice of runes · 3.9 Summary

What you learn in chapter 3 →

Chapter 4: Collection types

Introduces Go’s built-in collection types and the kinds of data each is suited to holding.

4.1 Arrays · 4.1.1 Declaring arrays · 4.1.2 Array type and length · 4.1.3 Working with array elements · 4.1.4 Iterating over arrays with for · 4.1.5 Arrays as values · 4.1.6 Multidimensional arrays · 4.1.7 Passing arrays to functions · 4.1.8 The problem with arrays · 4.2 Slices · 4.2.1 Declaring slices with slice literals · 4.2.2 Declaring slices with make · 4.2.3 Nil slices · 4.2.4 Growing slices with append · 4.2.5 Avoiding append surprises · 4.2.6 Slice expressions · 4.2.7 Copying slices with copy · 4.2.8 Avoiding runtime panics when accessing slice values · 4.2.9 Nil slices versus empty slices · 4.3 Maps · 4.3.1 Declaring maps · 4.3.2 Setting and accessing map values · 4.3.3 Removing values from maps · 4.3.4 Getting the number of values in a map · 4.3.5 Iterating over maps · 4.3.6 Passing maps to functions · 4.3.7 Key and value types · 4.4 Summary

What you learn in chapter 4 →

Chapter 5: Working with types

This chapter introduction explains why Go’s type system helps model real-world domains safely and previews the type features used in a recipe application.

5.1 Modeling a domain with types · 5.1.1 Named types · 5.1.2 Structs · 5.2 Extending types · 5.2.1 Type embedding · 5.2.2 Complex types · 5.3 Pointer types · 5.4 Methods and behavior · 5.5 Interfaces · 5.6 Checking types · 5.6.1 Type composition and wrapping · 5.6.2 Example: Putting it all together · 5.7 Summary

What you learn in chapter 5 →

Chapter 6: Generics

Introduces Go generics as a type-safe layer of abstraction and previews the chapter’s progression from type parameters to reusable collections and standard-library utilities.

6.1 Typed parameters in generics · 6.1.1 Using interface constraints · 6.1.2 Defining custom constraints · 6.1.3 Using underlying types with tilde (~) · 6.1.4 Summary of type constraints · 6.2 Implementing generic functions · 6.3 Implementing generic interfaces · 6.4 Multiple type parameters · 6.5 Limitations and considerations · 6.5.1 Performance considerations · 6.5.2 Limitations of Go generics · 6.5.3 Common gotchas · 6.5.4 When to use generics · 6.5.5 Backward compatibility · 6.6 Standard library support · 6.6.1 The constraints package · 6.6.2 The slices and maps packages · 6.6.3 The cmp package · 6.7 Just getting started · 6.8 Summary

What you learn in chapter 6 →

Chapter 7: Errors in Go

The introduction explains why software must handle unexpected conditions and previews Go’s explicit, flexible approach to errors through a small key/value database example.

7.1 Go errors are values · 7.2 The Go error type · 7.3 Generating new errors · 7.4 Handling errors · 7.5 Logging errors · 7.6 Annotating error logs with formatting · 7.7 Sentinel errors · 7.8 Identifying different types of errors · 7.9 Creating a custom error type · 7.10 Getting the underlying error with errors.As · 7.11 An unexpected error journey · 7.12 Don’t panic · 7.12.1 Using Panic and Recover in your code · 7.13 Summary

What you learn in chapter 7 →

Chapter 8: Testing and tooling

This chapter introduction presents Go testing as more than a way to check finished code: tests can guide development, reveal performance problems, and find bugs in unexpected inputs.

8.1 Test files and functions · 8.2 Running tests with go test · 8.3 Test functions · 8.4 Test life cycle · 8.5 Test-driven design: A calculator with a twist · 8.5.1 Black-box testing · 8.5.2 Writing tests for error conditions · 8.5.3 Writing good test logs · 8.5.4 Choosing testing targets · 8.5.5 Table-driven testing · 8.5.6 Implementation and initial testing · 8.5.7 Code coverage · 8.6 Simulating dependencies with an HTTP server · 8.7 Beyond unit tests · 8.7.1 Benchmark testing · 8.7.2 Fuzz testing · 8.8 Summary

What you learn in chapter 8 →

Chapter 9: Concurrency

The chapter introduces the difference between concurrency and parallelism, explains why concurrency helps applications stay responsive, and previews Go’s tools for concurrent work.

9.1 When to use concurrency · 9.2 Sync package · 9.2.1 Wait groups · 9.2.2 Error Groups · 9.2.3 Mutexes · 9.3 Adding some context · 9.4 Channels · 9.5 Concurrency patterns · 9.5.1 Workers · 9.5.2 Fan-out and fan-in · 9.6 Helpful concurrency tips · 9.6.1 Best practices for Go concurrency · 9.6.2 When to use concurrency in Go · 9.6.3 When not to use concurrency in Go · 9.7 Summary

What you learn in chapter 9 →

Chapter 10: The standard library

The introduction presents Go’s standard library and previews a chapter-long JSON and XML utility built by combining its packages.

10.1 The fmt package · 10.2 The flag package · 10.3 The io package · 10.4 The os package · 10.5 The encoding package · 10.5.1 JSON processing · 10.5.2 XML processing · 10.6 The bufio package · 10.7 The regexp package · 10.8 The strings package · 10.9 The strconv package · 10.10 Scratching the surface · 10.11 Summary

What you learn in chapter 10 →

Chapter 11: Working with larger projects

The chapter introduces Go’s packages, modules, versions, and workspaces as tools for turning a small RSS application into an organized multimodule project.

11.1 Modules · 11.1.1 Packages · 11.1.2 Domain module: Shared domain model · 11.2 Versioning modules · 11.3 Workspaces · 11.3.1 Understanding workspaces · 11.3.2 API module: REST service · 11.3.3 Worker module: Background feed fetcher · 11.3.4 Testing the complete system · 11.3.5 Versioning independent modules · 11.3.6 Workspace benefits demonstrated · 11.4 Summary

What you learn in chapter 11 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.