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)
Network Programming

The Go standard library provides a lot of support for network operations. It includes packages that allow you to manage TCP/IP, UDP, DNS, mail, and RPC using HTTP. Third-party packages can also fill in the gaps from what's included in the standard library, including gorilla/websockets (https://github.com/gorilla/websocket/) for a WebSocket implementation that can be used in a normal HTTP handler. This chapter explores these libraries and demonstrates some simple recipes for how you can make use of each of them. These recipes will assist developers who are unable to use a higher-level abstraction such as REST or GRPC, but need network connectivity. It's also useful for DevOps applications that need to perform DNS lookups or work with raw emails. After reading this chapter, you should've gained some mastery of basic networking programming and be prepared to dive deeper.

In this chapter...