Book Image

Go Programming Cookbook - Second Edition

By : Aaron Torres
Book Image

Go Programming Cookbook - Second Edition

By: Aaron Torres

Overview of this book

Go (or Golang) is a statically typed programming language developed at Google. Known for its vast standard library, it also provides features such as garbage collection, type safety, dynamic-typing capabilities, and additional built-in types. This book will serve as a reference while implementing Go features to build your own applications. This Go cookbook helps you put into practice the advanced concepts and libraries that Golang offers. The recipes in the book follow best practices such as documentation, testing, and vendoring with Go modules, as well as performing clean abstractions using interfaces. You'll learn how code works and the common pitfalls to watch out for. The book covers basic type and error handling, and then moves on to explore applications, such as websites, command-line tools, and filesystems, that interact with users. You'll even get to grips with parallelism, distributed systems, and performance tuning. By the end of the book, you'll be able to use open source code and concepts in Go programming to build enterprise-class applications without any hassle.
Table of Contents (16 chapters)

What this book covers

Chapter 1, I/O and Filesystems, covers common Go I/O interfaces and explores working with filesystems. This includes temporary files, templates, and CSV files.

Chapter 2, Command-Line Tools, looks at taking in user input via the command line and explores processing common datatypes such as TOML, YAML, and JSON.

Chapter 3, Data Conversion and Composition, demonstrates methods for casting and converting between Go interfaces and data types. It also showcases encoding strategies and some functional design patterns for Go.

Chapter 4, Error Handling in Go, showcases strategies to handle errors in Go. It explores how to pass errors, handle them, and log them.

Chapter 5, Network Programming, demonstrates usage of various networking primitives such as UDP and TCP/IP. It also explores Domain Name System (DNS), working with raw email messages, and basic Remote Procedure Call (RPC).

Chapter 6, All about Databases and Storage, deals with various storage libraries for accessing data storage systems such as MySQL. It also demonstrates the use of interfaces to decouple your library from your application logic.

Chapter 7, Web Clients and APIs, implements Go HTTP client interfaces, REST clients, OAuth2 clients, decorating and extending clients, and gRPC.

Chapter 8, Microservices for Applications in Go, explores web handlers, passing in a state to a handler, validation of user input, and middleware.

Chapter 9, Testing Go Code, focuses on mocking, test coverage, fuzzing, behavior testing, and helpful testing tools.

Chapter 10, Parallelism and Concurrency, provides a reference for channels and async operations, atomic values, Go context objects, and channel state management.

Chapter 11, Distributed Systems, implements service discovery, Docker containerization, metrics and monitoring, and orchestration. It mostly deals with deployment and productionization of Go applications.

Chapter 12, Reactive Programming and Data Streams, explores reactive and dataflow applications, Kafka and distributed message queues, and GraphQL servers.

Chapter 13, Serverless Programming, deals with deploying Go applications without maintaining a server. This includes using Google App Engine, Firebase, Lambda, and logging in a serverless environment.

Chapter 14, Performance Improvements, Tips, and Tricks, deals with benchmarking, identifying bottlenecks, optimizing, and improving the HTTP performance for Go applications.