Book Details

ISBN 139781783286836

Paperback400 pages

Book Description

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

Chapter 1: I/O and File Systems

Introduction

Using the common I/O interfaces

Using the bytes and strings packages

Working with directories and files

Working with the CSV format

Working with temporary files

Working with text/template and HTML/templates

Chapter 2: Command-Line Tools

Introduction

Using command-line flags

Using command-line arguments

Reading and setting environment variables

Configuration using TOML, YAML, and JSON

Working with Unix pipes

Catching and handling signals

An ANSI coloring application

Chapter 3: Data Conversion and Composition

Introduction

Converting data types and interface casting

Working with numeric data types using math and math/big

Currency conversions and float64 considerations

Using pointers and SQL NullTypes for encoding and decoding

Encoding and decoding Go data

Struct tags and basic reflection in Go

Implementing collections via closures

Chapter 4: Error Handling in Go

Introduction

Handling errors and the Error interface

Using the pkg/errors package and wrapping errors

Using the log package and understanding when to log errors

Structured logging with the apex and logrus packages

Logging with the context package

Using package-level global variables

Catching panics for long running processes

Chapter 5: All about Databases and Storage

Introduction

The database/sql package with MySQL

Executing a database transaction interface

Connection pooling, rate limiting, and timeouts for SQL

Working with Redis

Using NoSQL with MongoDB and mgo

Creating storage interfaces for data portability

Chapter 6: Web Clients and APIs

Introduction

Initializing, storing, and passing http.Client structs

Writing a client for a REST API

Executing parallel and async client requests

Making use of OAuth2 clients

Implementing an OAuth2 token storage interface

Wrapping a client in added functionality and function composition

Understanding GRPC clients

Chapter 7: Microservices for Applications in Go

Introduction

Working with web handlers, requests, and ResponseWriters

Using structs and closures for stateful handlers

Validating input for Go structs and user inputs

Rendering and content negotiation

Implementing and using middleware

Building a reverse proxy application

Exporting GRPC as a JSON API

Chapter 8: Testing

Introduction

Mocking using the standard library

Using the Mockgen package

Using table-driven tests to improve coverage

Using third-party testing tools

Practical fuzzing

Behavior testing using Go

Chapter 9: Parallelism and Concurrency

Introduction

Using channels and the select statement

Performing async operations with sync.WaitGroup

Using atomic operations and mutex

Using the context package

Executing state management for channels

Using the worker pool design pattern

Using workers to create pipelines

Chapter 10: Distributed Systems

Introduction

Using service discovery with Consul

Implementing basic consensus using Raft

Using containerization with Docker

Orchestration and deployment strategies

Monitoring applications

Collecting metrics

Chapter 11: Reactive Programming and Data Streams

Introduction

Goflow for dataflow programming

Reactive programming with RxGo

Using Kafka with Sarama

Using async producers with Kafka

Connecting Kafka to Goflow

Writing a GraphQL server in Go

Chapter 12: Serverless Programming

Introduction

Go programming on Lambda with Apex

Apex serverless logging and metrics

Google App Engine with Go

Working with Firebase using zabawaba99/firego

Chapter 13: Performance Improvements, Tips, and Tricks

Introduction

Speeding up compilation and testing cycles

Using the pprof tool

Benchmarking and finding bottlenecks

Memory allocation and heap management

Vendoring and project layout

Using fasthttprouter and fasthttp

What You Will Learn

Test your application using advanced testing methodologies

Develop an awareness of application structures, interface design, and tooling

Authors

Aaron Torres

Aaron Torres received his master’s of science degree in computer science from New Mexico Institute of Mining and Technology. He has worked on distributed systems in high performance computing and in large-scale web and microservices applications. He currently leads a team of Go developers that refines and focuses on Go best practices with an emphasis on continuous delivery and automated testing.

Aaron has published a number of papers and has several patents in the area of storage and I/O. He is passionate about sharing his knowledge and ideas with others. He is also a huge fan of the Go language and open source for backend systems and development.

Alerts & Offers

Series & Level

We understand your time is important. Uniquely amongst the major publishers, we seek to develop and publish the broadest range of learning and information products on each technology. Every Packt product delivers a specific learning pathway, broadly defined by the Series type. This structured approach enables you to select the pathway which best suits your knowledge level, learning style and task objectives.

Learning

As a new user, these step-by-step tutorial guides will give you all the practical skills necessary to become competent and efficient.

Beginner's Guide

Friendly, informal tutorials that provide a practical introduction using examples, activities, and challenges.

Essentials

Fast paced, concentrated introductions showing the quickest way to put the tool to work in the real world.

Cookbook

A collection of practical self-contained recipes that all users of the technology will find useful for building more powerful and reliable systems.

Blueprints

Guides you through the most common types of project you'll encounter, giving you end-to-end guidance on how to build your specific solution quickly and reliably.

Mastering

Take your skills to the next level with advanced tutorials that will give you confidence to master the tool's most powerful features.

Starting

Accessible to readers adopting the topic, these titles get you into the tool or technology so that you can become an effective user.

Progressing

Building on core skills you already have, these titles share solutions and expertise so you become a highly productive power user.