322
334 323
335 324
336 325
337 326
338 327
339 328
340 329
341 330
342 331
343 332
344 333
345 334
346 335
347 336
348 337
349 338
350 339
351 340
352 341
353 342
354 343
355 344
356 345
357 346
358 347
359 348
360 349
361 350
362 351
363 352
364 353
365 354
366 355
367 356
368 357
369 358
370 359
371 360
372 361
373 362
374 363
375 364
376 365
377 366
378 367
379 368
380 369
381 370
382 371
383 372
384 373
385 375
386 376
387 377
388 378
389 379
390 380
391 381
392 382
393 383
394 384
395 385
396 386
397 ii
398 iii
399 v
400 vii
401 ix
402 387
NOTE A glossary of relevant terms is available for free download from the book's web page: https://www.wiley.com/go/practicalgo.
Practical Go
Building Scalable Network and Non-Network Applications
Amit Saha
Introduction
Google announced the Go programming language to the public in 2009, with the version 1.0 release announced in 2012. Since its announcement to the community, and the compatibility promise of the 1.0 release, the Go language has been used to write scalable and high-impact software programs ranging from command-line applications and critical infrastructure tools to large-scale distributed systems. The Go language has made a huge contribution to the growth of a number of modern software success stories. For a number of years, my personal interest in Go has been due to its, for the lack of a better word, boring nature—that's what I like about it. It felt like it combined the power of the second programming language I learned, C, with the batteries-included approach of another favorite language of mine, Python. As I have written more programs using the Go language, I have learned to appreciate its focus on providing all the necessary tools and features to write production-quality software. I have often found myself thinking, “Will I be able to implement this failure-handling pattern in this application?” Then I look at the standard library package documentation, and the answer has always been a resounding “Yes!” Once you have grasped the fundamentals of Go, with almost zero effort on your part as the software developer, the result is a highly performant application out of the box.
My goal in this book is to showcase the various features of the Go language and the standard libraries (along with a few community-maintained packages) by developing various categories of applications. Once you have refreshed or learned the language fundamentals, this book will help you take the next step. I have adopted a writing style where the focus is on using various features of the language and its libraries to solve the particular problem at hand—one that you care about.
You will not find a detailed walk-through of a language feature or every feature of a certain package. You will learn just enough to build a command-line tool, a web application, or a gRPC application. I focus on a strictly chosen subset of the fundamental building blocks for such applications to provide a compact and actionable guide. Hence, you may find that the book doesn't cover the more higher-level use cases that you may want to learn about. That is intentional, as the implementation of those higher-level use cases is often dependent on domain-specific software packages, and hence no single book can do justice to recommending one without missing out on another. I also strive to use standard library packages as far as possible for writing the applications in the book. This is again done to ensure that the learning experience is not diluted. Nonetheless, I hope that the building blocks you learn about in the book will provide you with a solid foundation to leverage higher-level libraries to build your applications.
What Does This Book Cover?
This book teaches you concepts and demonstrates patterns to build various categories of applications using the Go programming language. We focus on command-line