Book Image

Mastering Go - Second Edition

By : Mihalis Tsoukalos
Book Image

Mastering Go - Second Edition

By: Mihalis Tsoukalos

Overview of this book

Often referred to (incorrectly) as Golang, Go is the high-performance systems language of the future. Mastering Go, Second Edition helps you become a productive expert Go programmer, building and improving on the groundbreaking first edition. Mastering Go, Second Edition shows how to put Go to work on real production systems. For programmers who already know the Go language basics, this book provides examples, patterns, and clear explanations to help you deeply understand Go’s capabilities and apply them in your programming work. The book covers the nuances of Go, with in-depth guides on types and structures, packages, concurrency, network programming, compiler design, optimization, and more. Each chapter ends with exercises and resources to fully embed your new knowledge. This second edition includes a completely new chapter on machine learning in Go, guiding you from the foundation statistics techniques through simple regression and clustering to classification, neural networks, and anomaly detection. Other chapters are expanded to cover using Go with Docker and Kubernetes, Git, WebAssembly, JSON, and more. If you take the Go programming language seriously, the second edition of this book is an essential guide on expert techniques.
Table of Contents (20 chapters)
Title Page

Go maps

A Go map is equivalent to the well-known hash table found in many other programming languages. The main advantage of maps is that they can use any data type as their index, which in this case is called a map key or just a key. Although Go maps do not exclude any data types from being used as keys, for a data type to be used as a key it must be comparable, which means that the Go compiler must be able to differentiate one key from another or, putting it simply, that the keys of a map must support the == operator.

The good news is that almost all data types are comparable. However, as you can imagine, using the bool data type as the key to a map will definitely limit your options. Additionally, using floating-point numbers as keys might present problems caused by the precision used for different machines and operating systems.

As mentioned, a Go map is a reference to a hash...