-
Book Overview & Buying
-
Table Of Contents
Practical Systems Programming in Go
By :
Welcome to the 1st Edition of Practical Systems Programming in Go! As the Go programming language continues to evolve and gain popularity, it has emerged as a language of choice for building scalable, performant, and maintainable systems software. Whether you are a seasoned Go developer looking to deepen your expertise or a newcomer eager to master the intricacies of the language, this book is your comprehensive guide.
While there are many books that teach Go as a general-purpose language, systems programming demands a different depth of understanding. Writing software that interacts directly with the operating system, manages files and signals, communicates over networks, processes structured data at scale, and squeezes performance out of concurrent workloads requires both a firm grasp of Go internals and a practical understanding of how modern UNIX systems work. Go is particularly well-suited for this domain — its standard library is rich, its concurrency model is powerful, and its compiled nature makes it fast enough for low-level work without sacrificing the readability and simplicity that developers love. Yet these topics are rarely treated together in a single, focused resource. This book fills that gap.
There are many exciting topics in this edition, including working with file I/O, Unix signals and file systems, programming TCP/IP services and web services, working with structured data and databases, and exploring time series distances and data mining. The book also features a particularly unique and rewarding journey into writing your own programming language from scratch and extending it with new features.
In the tradition of foundational texts like The UNIX Programming Environment and The C Programming Language, this book adopts a deliberate and detailed explanatory style. Rather than offering a superficial overview of syntax, we prioritize the logic behind every architectural decision. Systems programming is as much about understanding the constraints of the machine as it is about writing code; therefore, we pause frequently to examine the why. By engaging with these deep-dives, you are not merely learning a language but internalizing a philosophy of systems construction. We treat the code as a vehicle for understanding broader engineering trade-offs, from the durability of a Write-Ahead Log to the resource limits of filesystem watchers. While this level of detail requires a more patient reading experience, the reward is a mental model that remains stable long after specific library versions have evolved. Setting this expectation upfront ensures that our journey through the stack is both rewarding and practical, transforming abstract concepts into the intuitive tools of a master craftsman.
Thank you for choosing Practical Systems Programming in Go. Let's dive in and unlock the full potential of Go together! Happy coding!
Soli Deo gloria
This book is for amateur and intermediate Go programmers who want to take their Go knowledge to the next level, as well as developers in other programming languages who want to learn systems programming in UNIX using Go.
If this is your first systems programming book, some sections may challenge you, and a second reading will often reveal details that were not immediately obvious the first time around. Do not be discouraged by this — it is perfectly normal.
Throughout the book, you will find practical examples and exercises designed to ground abstract concepts in real, working code. The best way to learn systems programming is to actually do it, so resist the temptation to skip them.
Finally, be prepared to struggle. You will write code that does not work, chase bugs that make no sense, and revisit ideas you thought you had already understood. That is not a sign that you are doing something wrong — it is the process. Push through it, and the rewards are well worth the effort.
Chapter 1, Essential Go, introduces the Go programming language, covering its core syntax, basic types, control flow, functions, and the tools you need to write, build, and run Go programs. In this chapter, we present arrays and slices and implement two traditional UNIX command line tools: which(1) and basename(1).
Chapter 2, Data Collections and Functions, explores maps and structures alongside a deeper treatment of pointers, functions, closures, and variadic parameters. By the end of this chapter, you will be comfortable organizing and manipulating data in idiomatic Go.
Chapter 3, Go Concurrency, covers goroutines, channels, select, the sync package, and the patterns that make concurrent Go programs correct and efficient. We examine how to avoid race conditions and deadlocks, and how to coordinate work across multiple goroutines.
Chapter 4, Advanced Go, dives into interfaces, reflection, generics, and other language features that separate competent Go programmers from expert ones, as well as working with dates and times, testing and benchmarking Go code, and creating your own package. This chapter equips you with the tools to write flexible, reusable, and robust code while knowing what happens behind the scenes.
Chapter 5, Working with File I/O, is about reading from and writing to files, working with the io.Reader and io.Writer interfaces, buffered I/O, and the standard library packages that make file handling in Go both powerful and ergonomic. In this chapter, we create a wc(1) clone.
Chapter 6, UNIX Signals and File Systems, covers how Go programs interact with the operating system at a deeper level, including handling UNIX signals gracefully, navigating and manipulating the file system, and understanding the implications of these operations in long-running system processes. In Chapter 6, we develop a version of tree(1) and dd(1) in Go.
Chapter 7, Working with Structured Data and Databases, discusses parsing and producing structured data formats such as JSON and CSV, as well as interacting with relational and other databases. We build practical utilities that store, retrieve, and process data reliably, and a utility that creates reports. The database of choice is going to be SQLite3, but we are also going to create an example using PostgreSQL.
Chapter 8, Programming TCP/IP Services, explores the net package and the TCP and UDP protocols, developing practical client and server applications that communicate over the network at a low level. You learn how to collect metrics about TCP and UDP connections and make these metrics accessible to Prometheus.
Chapter 9, Creating Web Services, discusses the net/http package, the development of web servers and web services, the creation of web clients, and the timing out of HTTP connections while demonstrating how to build production-ready services. We show how to read data from Prometheus.
Chapter 10, Writing a Programming Language, takes an exciting detour into language design and implementation. We build a small interpreted programming language called SMALL from scratch in Go, covering lexing, parsing, and evaluation.
Chapter 11, Adding New Features to SMALL, continues the work of the previous chapter by extending SMALL with new capabilities, reinforcing how a real language evolves and how its interpreter must grow to accommodate it.
Chapter 12, Time Series Distances, introduces the concept of time series data and the algorithms used to measure similarity and distance between sequences, implementing a practical Go package along the way. Chapter 12 concludes by showing how to work with TigerBeetle, a high-performance distributed database designed for financial accounting.
Chapter 13, Time Series Data Mining, builds on the previous chapter to explore data mining techniques applied to time series, including classification, clustering, and outlier detection, all implemented in Go.
Chapter 14, Creating an Index for Unix Files, brings the book to a close with a substantial systems programming project: building a utility that indexes UNIX files, combining File I/O, data structures, and performance considerations into a complete, practical tool.
This book requires a modern computer with a relatively recent Go version installed, which includes any machine running Mac OS X, macOS, or Linux, as well as familiarity with your operating system, its filesystem, and git(1). Most of the presented code also runs on Microsoft Windows machines without any changes.
As you embark on your journey to mastering Go, I encourage you to experiment, ask questions, and engage with the material actively. The Go programming language offers a refreshing blend of simplicity and power, and I am confident that this book will provide you with the knowledge and skills needed to become a proficient Go developer.
The code bundle for the book is hosted on GitHub at https://github.com/mactsouk/goSP. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://packt.link/gbp/9781806112197.
There are a number of text conventions used throughout this book.
CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. For example: "Mount the downloaded WebStorm-10*.dmg disk image file as another disk in your system."
A block of code is set as follows:
package main
import "fmt"
func doubleSquare(x int) (int, int) {
return x * 2, x * x
}
Any command-line input or output is written as follows:
$ go run namedReturn.go 1 -2
-2 1
-2 1
Bold: Indicates a new term, an important word, or important information. For instance, words in menus or dialog boxes appear in the text like this. For example: "The next subsection illustrates the use of sync.WaitGroup for goroutine synchronization. "
Warnings or important notes appear like this
Tips and tricks appear like this
Feedback from our readers is always welcome.
General feedback: Email [email protected] and mention the book's title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you reported this to us. Please visit , click Submit Errata, and fill in the form.
Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit http://authors.packtpub.com.
Read this book alongside other users, developers, experts, and the author himself.
Ask questions, provide solutions to other readers, chat with the authors via Ask Me Anything sessions, and much more. Scan the QR code or visit the link to join the community.

Change the font size
Change margin width
Change background colour