Book Image

Go Cookbook

By : Aaron Torres
Book Image

Go Cookbook

By: Aaron Torres

Overview of this book

Go (a.k.a. Golang) is a statically-typed programming language first developed at Google. It is derived from C with additional features such as garbage collection, type safety, dynamic-typing capabilities, additional built-in types, and a large standard library. This book takes off where basic tutorials on the language leave off. You can immediately put into practice some of the more advanced concepts and libraries offered by the language while avoiding some of the common mistakes for new Go developers. The book covers basic type and error handling. It explores applications that interact with users, such as websites, command-line tools, or via the file system. It demonstrates how to handle advanced topics such as parallelism, distributed systems, and performance tuning. Lastly, it finishes with reactive and serverless programming in Go.
Table of Contents (14 chapters)

What this book covers

Chapter 1, I/O and File Systems, 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 a 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, 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 6, Web Clients and APIs, implements Go HTTP client interfaces, REST clients, OAuth2 clients, decorating and extending clients, and GRPC.

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

Chapter 8, Testing, focuses on mocking, test coverage, fuzzing, behavior testing, and helpful testing tools.

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

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

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

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

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