About the Author |
|
xv | |
About the Technical Reviewer |
|
xvii | |
Introduction |
|
xix | |
|
|
1 | (26) |
|
|
1 | (1) |
|
|
2 | (1) |
|
|
2 | (3) |
|
|
2 | (1) |
|
|
2 | (1) |
|
|
2 | (3) |
|
1-2 Setting Up Go Development Environment |
|
|
5 | (1) |
|
|
5 | (1) |
|
|
5 | (1) |
|
|
5 | (1) |
|
|
6 | (2) |
|
|
6 | (1) |
|
|
6 | (1) |
|
|
6 | (2) |
|
1-4 Building an Executable Program |
|
|
8 | (2) |
|
|
8 | (1) |
|
|
8 | (1) |
|
|
8 | (2) |
|
1-5 Writing a Package as a Shared Library |
|
|
10 | (4) |
|
|
10 | (1) |
|
|
10 | (1) |
|
|
10 | (4) |
|
1-6 Reusing a Shared Library Package |
|
|
14 | (1) |
|
|
14 | (1) |
|
|
14 | (1) |
|
|
14 | (1) |
|
1-7 Managing Source Code Using Go Tool |
|
|
15 | (4) |
|
|
15 | (1) |
|
|
15 | (1) |
|
|
15 | (4) |
|
1-8 Writing and Reusing Packages |
|
|
19 | (8) |
|
|
19 | (1) |
|
|
20 | (1) |
|
|
20 | (7) |
|
Chapter 2 Go Fundamentals |
|
|
27 | (26) |
|
2-1 Writing Functions in Go |
|
|
27 | (6) |
|
|
27 | (1) |
|
|
27 | (1) |
|
|
27 | (6) |
|
|
33 | (4) |
|
|
33 | (1) |
|
|
33 | (1) |
|
|
33 | (4) |
|
2-3 Working with Dynamic Arrays Using Slices |
|
|
37 | (4) |
|
|
37 | (1) |
|
|
37 | (1) |
|
|
37 | (4) |
|
2-4 Persisting Key/Value Pairs Using Map |
|
|
41 | (4) |
|
|
41 | (1) |
|
|
41 | (1) |
|
|
41 | (4) |
|
2-5 Writing Clean-Up Code in Functions |
|
|
45 | (1) |
|
|
45 | (1) |
|
|
45 | (1) |
|
|
45 | (1) |
|
2-6 Stopping the Execution Flow of Control Using Panic |
|
|
46 | (1) |
|
|
46 | (1) |
|
|
46 | (1) |
|
|
46 | (1) |
|
2-7 Recovering a Panicking Function Using Recover |
|
|
47 | (1) |
|
|
47 | (1) |
|
|
47 | (1) |
|
|
47 | (1) |
|
2-8 Performing Error Handling |
|
|
48 | (5) |
|
|
48 | (1) |
|
|
48 | (1) |
|
|
49 | (4) |
|
Chapter 3 Structs and Interfaces |
|
|
53 | (22) |
|
3-1 Creating User-Defined Types |
|
|
53 | (3) |
|
|
53 | (1) |
|
|
53 | (1) |
|
|
53 | (3) |
|
3-2 Adding Methods to Struct Types |
|
|
56 | (6) |
|
|
56 | (1) |
|
|
56 | (1) |
|
|
56 | (6) |
|
3-3 Composing Types Using Type Embedding |
|
|
62 | (5) |
|
|
62 | (1) |
|
|
62 | (1) |
|
|
62 | (5) |
|
3-4 Working with Interfaces |
|
|
67 | (8) |
|
|
67 | (1) |
|
|
67 | (1) |
|
|
67 | (8) |
|
|
75 | (28) |
|
4-1 Writing Concurrent Programs |
|
|
75 | (4) |
|
|
75 | (1) |
|
|
75 | (1) |
|
|
75 | (4) |
|
4-2 Managing the Number of CPUs in Concurrency |
|
|
79 | (1) |
|
|
79 | (1) |
|
|
80 | (1) |
|
|
80 | (1) |
|
|
80 | (4) |
|
|
80 | (1) |
|
|
80 | (1) |
|
|
80 | (4) |
|
4-4 Using Channels for Synchronous Communication |
|
|
84 | (5) |
|
|
84 | (1) |
|
|
84 | (1) |
|
|
84 | (5) |
|
4-5 Using the Output of One Goroutine as the Input of Another |
|
|
89 | (5) |
|
|
89 | (1) |
|
|
89 | (1) |
|
|
90 | (4) |
|
4-6 Using Channels for Asynchronous Communication |
|
|
94 | (5) |
|
|
94 | (1) |
|
|
94 | (1) |
|
|
95 | (4) |
|
4-7 Communicating on Multiple Channels |
|
|
99 | (4) |
|
|
99 | (1) |
|
|
99 | (1) |
|
|
99 | (4) |
|
Chapter 5 Using Standard Library Packages |
|
|
103 | (26) |
|
5-1 Encoding and Decoding JSON |
|
|
103 | (5) |
|
|
103 | (1) |
|
|
103 | (1) |
|
|
103 | (5) |
|
5-2 Using Command-Line Flags |
|
|
108 | (3) |
|
|
108 | (1) |
|
|
108 | (1) |
|
|
108 | (3) |
|
|
111 | (7) |
|
|
111 | (1) |
|
|
111 | (1) |
|
|
111 | (7) |
|
5-4 Archiving Files in Tar and Zip Formats |
|
|
118 | (11) |
|
|
118 | (1) |
|
|
118 | (1) |
|
|
118 | (11) |
|
Chapter 6 Data Persistence |
|
|
129 | (40) |
|
6-1 Persisting Data with MongoDB |
|
|
129 | (12) |
|
|
129 | (1) |
|
|
129 | (1) |
|
|
129 | (2) |
|
|
131 | (1) |
|
Performing CRUD Operations |
|
|
131 | (10) |
|
6-2 Persisting Data with RethinkDB |
|
|
141 | (12) |
|
|
141 | (1) |
|
|
141 | (1) |
|
|
142 | (11) |
|
6-3 Working on Time Series Data with InfluxDB |
|
|
153 | (9) |
|
|
153 | (1) |
|
|
153 | (1) |
|
|
154 | (8) |
|
6-4 Working with SQL Databases |
|
|
162 | (7) |
|
|
162 | (1) |
|
|
162 | (1) |
|
|
162 | (7) |
|
Chapter 7 Building HTTP Servers |
|
|
169 | (36) |
|
7-1 Creating Custom HTTP Handlers |
|
|
170 | (4) |
|
|
170 | (1) |
|
|
170 | (1) |
|
|
170 | (4) |
|
7-2 Using an Adapter to Use Normal Functions as Handlers |
|
|
174 | (2) |
|
|
174 | (1) |
|
|
175 | (1) |
|
|
175 | (1) |
|
7-3 Using Normal Functions as HTTP Handlers Using ServeMux.HandleFunc |
|
|
176 | (2) |
|
|
176 | (1) |
|
|
176 | (1) |
|
|
176 | (2) |
|
7-4 Using Default ServeMux Value |
|
|
178 | (1) |
|
|
178 | (1) |
|
|
178 | (1) |
|
|
178 | (1) |
|
7-5 Customizing http.Server |
|
|
179 | (1) |
|
|
179 | (1) |
|
|
179 | (1) |
|
|
179 | (1) |
|
7-6 Writing HTTP Middleware |
|
|
180 | (3) |
|
|
180 | (1) |
|
|
180 | (1) |
|
|
181 | (2) |
|
7-7 Writing RESTful API with Go and MongoDB |
|
|
183 | (22) |
|
|
183 | (1) |
|
|
183 | (1) |
|
|
183 | (22) |
|
Chapter 8 Testing Go Applications |
|
|
205 | (30) |
|
|
205 | (3) |
|
|
205 | (1) |
|
|
205 | (1) |
|
|
205 | (3) |
|
8-2 Skipping Long-Running Tests |
|
|
208 | (2) |
|
|
208 | (1) |
|
|
208 | (1) |
|
|
209 | (1) |
|
8-3 Writing Benchmark Tests |
|
|
210 | (2) |
|
|
210 | (1) |
|
|
211 | (1) |
|
|
211 | (1) |
|
8-4 Running Unit Tests in Parallel |
|
|
212 | (2) |
|
|
212 | (1) |
|
|
212 | (1) |
|
|
212 | (2) |
|
8-5 Writing Tests for Verifying Example Code |
|
|
214 | (2) |
|
|
214 | (1) |
|
|
214 | (1) |
|
|
214 | (2) |
|
8-6 Testing HTTP Applications |
|
|
216 | (5) |
|
|
216 | (1) |
|
|
216 | (1) |
|
|
216 | (5) |
|
8-7 Writing BDD-Style Tests |
|
|
221 | (14) |
|
|
221 | (1) |
|
|
221 | (1) |
|
|
221 | (14) |
Index |
|
235 | |