Introduction |
|
1 | (4) |
|
|
1 | (1) |
|
|
2 | (1) |
|
|
2 | (1) |
|
|
3 | (1) |
|
|
3 | (2) |
|
PART 1 GETTING STARTED WITH GO |
|
|
5 | (74) |
|
|
7 | (16) |
|
Seeing What Learning Go Can Do for You |
|
|
8 | (1) |
|
Installing Go on Your Machine |
|
|
9 | (1) |
|
|
10 | (1) |
|
|
11 | (1) |
|
Using an Integrated Development Environment with Go |
|
|
12 | (2) |
|
Writing Your First Go Program |
|
|
14 | (1) |
|
Compiling and running the program |
|
|
15 | (2) |
|
Understanding how a Go program works |
|
|
17 | (1) |
|
Making sense of the Go file structure |
|
|
18 | (1) |
|
Compiling for multiple operating systems |
|
|
19 | (2) |
|
Comparing Go with Other Languages |
|
|
21 | (1) |
|
|
21 | (1) |
|
|
22 | (1) |
|
|
22 | (1) |
|
|
22 | (1) |
|
Chapter 2 Working with Different Data Types |
|
|
23 | (14) |
|
Declaring Always-Changing Variables |
|
|
24 | (1) |
|
Using the var keyword: Type-inferred variables |
|
|
24 | (1) |
|
Specifying the data type: Explicitly typed variables |
|
|
25 | (1) |
|
Using the short variable declaration operator |
|
|
26 | (1) |
|
Declaring Never-Changing Constants |
|
|
27 | (1) |
|
Removing Unused Variables |
|
|
27 | (2) |
|
|
29 | (1) |
|
Performing Type Conversions |
|
|
30 | (1) |
|
Discovering the type of a variable |
|
|
31 | (1) |
|
Converting a variable's type |
|
|
32 | (2) |
|
|
34 | (3) |
|
Chapter 3 Making Decisions |
|
|
37 | (14) |
|
Using If/Else Statements to Make Decisions |
|
|
37 | (1) |
|
Laying the foundation for the if/else statement: Logical and comparison operators |
|
|
38 | (2) |
|
Using the if/else statement |
|
|
40 | (2) |
|
Short-circuiting: Evaluating conditions in Go |
|
|
42 | (4) |
|
When You Have Too Many Conditions: Using the Switch Statement |
|
|
46 | (1) |
|
Switching with fall-throughs |
|
|
47 | (1) |
|
|
48 | (1) |
|
Switching without condition |
|
|
48 | (3) |
|
Chapter 4 Over and Over and Over: Using Loops |
|
|
51 | (14) |
|
Performing Loops Using the for Statement |
|
|
51 | (5) |
|
Iterating over a Range of Values |
|
|
56 | (1) |
|
Iterating through arrays/slices |
|
|
56 | (2) |
|
Iterating through a string |
|
|
58 | (1) |
|
Using Labels with the for Loop |
|
|
59 | (6) |
|
Chapter 5 Grouping Code into Functions |
|
|
65 | (14) |
|
|
65 | (1) |
|
Defining functions with parameters |
|
|
66 | (2) |
|
Defining functions with multiple parameters |
|
|
68 | (1) |
|
Passing arguments by value and by pointer |
|
|
68 | (3) |
|
Returning values from functions |
|
|
71 | (1) |
|
|
72 | (1) |
|
Working with variadic functions |
|
|
72 | (1) |
|
Using Anonymous Functions |
|
|
73 | (1) |
|
Declaring an anonymous function |
|
|
73 | (1) |
|
Implementing closure using anonymous functions |
|
|
74 | (2) |
|
Implementing the filter() function using closure |
|
|
76 | (3) |
|
PART 2 WORKING WITH DATA STRUCTURES |
|
|
79 | (84) |
|
Chapter 6 Slicing and Dicing Using Arrays and Slices |
|
|
81 | (20) |
|
Arming Yourself to Use Arrays |
|
|
81 | (1) |
|
|
82 | (1) |
|
|
83 | (1) |
|
Working with multidimensional arrays |
|
|
83 | (3) |
|
Sleuthing Out the Secrets of Slices |
|
|
86 | (1) |
|
|
86 | (2) |
|
Creating and initializing a slice |
|
|
88 | (1) |
|
|
88 | (4) |
|
|
92 | (1) |
|
Extracting part of an array or slice |
|
|
92 | (3) |
|
Iterating through a slice |
|
|
95 | (1) |
|
Making copies of an array or slice |
|
|
95 | (2) |
|
Inserting an item into a slice |
|
|
97 | (2) |
|
Removing an item from a slice |
|
|
99 | (2) |
|
Chapter 7 Defining the Blueprints of Your Data Using Structs |
|
|
101 | (12) |
|
Defining Structs for a Collection of Items |
|
|
101 | (3) |
|
|
104 | (1) |
|
Making a Copy of a Struct |
|
|
105 | (2) |
|
Defining Methods in Structs |
|
|
107 | (3) |
|
|
110 | (3) |
|
Chapter 8 Establishing Relationships Using Maps |
|
|
113 | (16) |
|
|
113 | (2) |
|
Initializing a map with a map literal |
|
|
115 | (1) |
|
Checking the existence of a key |
|
|
115 | (1) |
|
|
116 | (1) |
|
Getting the number of items in a map |
|
|
116 | (1) |
|
|
117 | (1) |
|
Getting all the keys in a map |
|
|
117 | (1) |
|
Setting the iteration order in a map |
|
|
118 | (1) |
|
Sorting the items in a map by values |
|
|
118 | (3) |
|
Using Structs and Maps in Go |
|
|
121 | (1) |
|
Creating a map of structs |
|
|
121 | (3) |
|
|
124 | (5) |
|
Chapter 9 Encoding and Decoding Data UsingJSON |
|
|
129 | (22) |
|
Getting Acquainted with JSON |
|
|
129 | (1) |
|
|
130 | (1) |
|
|
130 | (1) |
|
|
131 | (1) |
|
|
131 | (1) |
|
|
132 | (1) |
|
|
132 | (1) |
|
|
133 | (1) |
|
|
134 | (1) |
|
Decoding JSON to a struct |
|
|
135 | (1) |
|
|
136 | (1) |
|
Decoding embedded objects |
|
|
137 | (3) |
|
Mapping custom attribute names |
|
|
140 | (1) |
|
Mapping unstructured data |
|
|
141 | (3) |
|
|
144 | (1) |
|
|
144 | (4) |
|
Encoding interfaces to JSON |
|
|
148 | (3) |
|
Chapter 10 Defining Method Signatures Using Interfaces |
|
|
151 | (12) |
|
Working with Interfaces in Go |
|
|
152 | (1) |
|
|
152 | (1) |
|
Implementing an interface |
|
|
153 | (1) |
|
Looking at How You May Use Interfaces |
|
|
154 | (4) |
|
Adding methods to a type that doesn't satisfy an interface |
|
|
158 | (1) |
|
Using the Stringer interface |
|
|
159 | (1) |
|
Implementing multiple interfaces |
|
|
160 | (1) |
|
|
161 | (1) |
|
Determining whether a value implements a specific interface |
|
|
162 | (1) |
|
PART 3 MULTITASKING IN GO |
|
|
163 | (32) |
|
Chapter 11 Threading Using Goroutines |
|
|
165 | (14) |
|
|
166 | (2) |
|
Using Goroutines with Shared Resources |
|
|
168 | (1) |
|
Seeing how shared resources impact goroutines |
|
|
168 | (3) |
|
Accessing shared resources using mutual exclusion |
|
|
171 | (1) |
|
Using atomic counters for modifying shared resources |
|
|
172 | (2) |
|
|
174 | (5) |
|
Chapter 12 Communicating between Goroutines Using Channels |
|
|
179 | (16) |
|
|
179 | (1) |
|
|
180 | (3) |
|
|
183 | (3) |
|
Iterating through Channels |
|
|
186 | (1) |
|
Asynchronously Waiting on Channels |
|
|
187 | (5) |
|
|
192 | (3) |
|
PART 4 ORGANIZING YOUR CODE |
|
|
195 | (28) |
|
Chapter 13 Using and Creating Packages in Go |
|
|
197 | (14) |
|
|
197 | (3) |
|
Creating shareable packages |
|
|
200 | (2) |
|
Organizing packages using directories |
|
|
202 | (2) |
|
Using Third-Party Packages |
|
|
204 | (1) |
|
|
204 | (1) |
|
|
205 | (6) |
|
Chapter 14 Grouping Packages into Modules |
|
|
211 | (12) |
|
|
211 | (3) |
|
Testing and Building a Module |
|
|
214 | (2) |
|
Publishing a Module on GitHub |
|
|
216 | (7) |
|
PART 5 SEEING GO IN ACTION |
|
|
223 | (62) |
|
Chapter 15 Consuming Web APIs Using Go |
|
|
225 | (18) |
|
|
225 | (1) |
|
Fetching Data from Web Services in Go |
|
|
226 | (1) |
|
Writing a Go program to connect to a web API |
|
|
227 | (2) |
|
|
229 | (4) |
|
Refactoring the code for decodingJSON data |
|
|
233 | (5) |
|
Fetching from multiple web services at the same time |
|
|
238 | (1) |
|
Returning Coroutine's results to the main() function |
|
|
239 | (4) |
|
Chapter 16 Getting Ready to Serve Using REST APIs |
|
|
243 | (28) |
|
Building Web Services Using REST APIs |
|
|
243 | (1) |
|
|
244 | (1) |
|
|
244 | (2) |
|
|
246 | (2) |
|
|
248 | (1) |
|
Creating a REST API in Go |
|
|
249 | (1) |
|
Getting your REST API up and running |
|
|
249 | (2) |
|
|
251 | (1) |
|
Registering additional paths |
|
|
251 | (3) |
|
|
254 | (1) |
|
Specifying request methods |
|
|
255 | (2) |
|
Storing the course information on the REST API |
|
|
257 | (10) |
|
Testing the REST API again |
|
|
267 | (4) |
|
Chapter 17 Working with Databases |
|
|
271 | (14) |
|
Setting Up a MySQL Database Server |
|
|
272 | (1) |
|
Interfacing with the MySQL server |
|
|
272 | (2) |
|
Creating a database and table |
|
|
274 | (1) |
|
Creating a new account and granting permission |
|
|
275 | (1) |
|
Connecting to the MySQL Database in Go |
|
|
276 | (2) |
|
|
278 | (2) |
|
|
280 | (1) |
|
|
281 | (2) |
|
|
283 | (2) |
|
|
285 | (18) |
|
Chapter 18 Ten Useful Go Packages to Create Applications |
|
|
287 | (12) |
|
|
287 | (1) |
|
|
288 | (1) |
|
|
288 | (1) |
|
|
288 | (1) |
|
|
288 | (1) |
|
|
288 | (1) |
|
|
289 | (1) |
|
|
289 | (1) |
|
|
289 | (1) |
|
|
290 | (1) |
|
|
290 | (1) |
|
|
290 | (1) |
|
|
291 | (1) |
|
|
291 | (1) |
|
|
291 | (1) |
|
|
292 | (1) |
|
|
293 | (1) |
|
|
293 | (1) |
|
|
294 | (1) |
|
|
294 | (1) |
|
|
294 | (1) |
|
|
295 | (1) |
|
|
295 | (1) |
|
|
295 | (1) |
|
|
296 | (1) |
|
|
296 | (1) |
|
|
296 | (1) |
|
|
297 | (1) |
|
|
297 | (1) |
|
|
297 | (2) |
|
Chapter 19 Ten Great Go Resources |
|
|
299 | (4) |
|
|
299 | (1) |
|
|
300 | (1) |
|
|
300 | (1) |
|
The Go Frequently Asked Questions |
|
|
300 | (1) |
|
|
300 | (1) |
|
|
301 | (1) |
|
|
301 | (1) |
|
|
301 | (1) |
|
|
301 | (1) |
|
|
302 | (1) |
Index |
|
303 | |