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 (15 chapters)

General Go coding advice

The following is a list of practical advice that will help you to write better Go code:

  • If you have an error in a Go function, either log it or return it; do not do both unless you have a really good reason for doing so.
  • Go interfaces define behaviors not data and data structures.
  • Use the io.Reader and io.Writer interfaces when possible because they make your code more extensible.
  • Make sure that you pass a pointer to a variable to a function only when needed. The rest of the time, just pass the value of the variable.
  • Error variables are not string variables; they are error variables!
  • Do not test your Go code on production machines unless you have a really good reason to do so.
  • If you do not really know a Go feature, test it before using it for the first time, especially if you are developing an application or a utility that will be used by a large number...