freeprogrammingbooks.com

How To Code in Go

By Mark Bates, Cory LaNou, Tim Raymond

How To Code in Go book cover

Go is a modern programming language created at Google to address the tension between fast compilation, ease of programming, and efficient execution in production. Since its public release in 2009, Go has become the language of choice for cloud infrastructure, distributed systems, microservices, and command-line tooling.

Its minimal syntax, built-in concurrency model, and fast compilation make it a practical option for teams building scalable backend services. Major platforms like Docker, Kubernetes, Terraform, and Prometheus are written in Go, and the language consistently ranks among the most in-demand skills for backend and DevOps roles.

About the book

How To Code in Go is a practical, self-contained introduction to the Go programming language written by members of the Gopher Guides team. The book assumes no prior experience with Go and guides readers from setting up a development environment through writing complete programs that handle errors, define custom types, and parse command-line flags. Each chapter focuses on a single topic with clear, standalone examples, making the book suitable both as a structured course for beginners and as a reference for experienced programmers who want to explore specific features.

What you will learn

The book starts with installation and environment setup on Ubuntu, macOS, and Windows, then moves through Go’s foundational concepts: data types, variables, constants, strings, operators, and boolean logic. Readers learn how to work with arrays, slices, and maps, handle errors and panics, write and organize packages, and control program flow with conditionals and loops. Later chapters cover functions (including variadic functions), defer and init, pointers, structs, methods, interfaces, and build tags. The book also explains how to cross-compile for different operating systems and architectures and how to use the flag package for CLI argument parsing.

Table of contents

  • How To Install Go and Set Up a Local Programming Environment on Ubuntu 18.04
  • How To Install Go and Set Up a Local Programming Environment on macOS
  • How To Install Go and Set Up a Local Programming Environment on Windows 10
  • How To Write Your First Program in Go
  • Understanding the GOPATH
  • How To Write Comments in Go
  • Understanding Data Types in Go
  • An Introduction to Working with Strings in Go
  • How To Format Strings in Go
  • An Introduction to the Strings Package in Go
  • How To Use Variables and Constants in Go
  • How To Convert Data Types in Go
  • How To Do Math in Go with Operators
  • Understanding Boolean Logic in Go
  • Understanding Maps in Go
  • Understanding Arrays and Slices in Go
  • Handling Errors in Go
  • Creating Custom Errors in Go
  • Handling Panics in Go
  • Importing Packages in Go
  • How To Write Packages in Go
  • Understanding Package Visibility in Go
  • How To Write Conditional Statements in Go
  • How To Write Switch Statements in Go
  • How To Construct For Loops in Go
  • Using Break and Continue Statements When Working with Loops in Go
  • How To Define and Call Functions in Go
  • How To Use Variadic Functions in Go
  • Understanding defer in Go
  • Understanding init in Go
  • Customizing Go Binaries with Build Tags
  • Understanding Pointers in Go
  • Defining Structs in Go
  • Defining Methods in Go
  • How To Build and Install Go Programs
  • How To Use Struct Tags in Go
  • How To Use Interfaces in Go
  • Building Go Applications for Different Operating Systems and Architectures
  • Using ldflags to Set Version Information for Go Applications
  • How To Use the Flag Package in Go

More books in: Go, Programming


Legal notice: This book is shared for educational purposes only. The content is distributed under Creative Commons licenses or with explicit permission from the author. FreeProgrammingBooks may host files that comply with their respective licenses.