Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Practical Systems Programming in Go
  • Table Of Contents Toc
Practical Systems Programming in Go

Practical Systems Programming in Go

By : Mihalis Tsoukalos
close
close
Practical Systems Programming in Go

Practical Systems Programming in Go

By: Mihalis Tsoukalos

Overview of this book

Go has become a leading language for Systems Programming thanks to its simplicity, strong concurrency model, and excellent performance. Practical Systems Programming in Go shows how to use Go beyond application development by building software that interacts with the operating system, networks, and data at scale. The book starts with a focused introduction to Go, covering the language features and standard packages most relevant to systems programming, including those handling concurrency, interfaces, testing, and runtime internals. It then moves into essential system-level topics such as file handling and I/O, UNIX signals, file systems, structured data formats, databases, and TCP/IP networking. Readers build practical command-line tools, web services, and network clients and servers along the way. In the final section, the book explores advanced applications, including writing an interpreter for a small programming language, processing time series data, building data-mining tools, and creating efficient indexes for UNIX file systems. By the end, readers will be able to design and implement robust systems software in Go for real-world environments.
Table of Contents (21 chapters)
close
close
Lock Free Chapter
1
Part 1: A quick introduction to Go
6
Part 2: Systems Programming Essentials
12
Part 3: Applications
20
Index

Preface

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

Who this book is for

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.

What this book covers

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.

To get the most out of this book

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.

Download the example code files

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!

Download the color images

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.

Conventions used

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

Get in touch

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.

Join us on Discord!

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.

Image 1

https://packt.link/deep-engineering-golang

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Practical Systems Programming in Go
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist download Download options font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon