Introduction

Let’s get an overview of the UNIX system.

We'll cover the following

Systems programming

This chapter teaches us about systems programming in Go. Systems programming involves working with files and directories, process control, signal handling, network programming, system files, configuration files, and file input and output (I/O). Docker images use the Linux operating system, which means that we might need to develop our utilities with the Linux operating system in mind. However, as Go code is portable, most system utilities work on Windows machines without any changes or with minor modifications. Among other things, this chapter implements two utilities: one that finds cycles in UNIX file systems and another that converts JSON data to XML data and vice versa. Additionally, in this chapter, we are going to improve the phone book application with the help of the cobra package.

Important note: Starting with Go 1.16, the GO111MODULE environment variable defaults to on—this affects the use of Go packages that do not belong to the Go standard library. In practice, this means that we must put our code under ~/go/src. We can go back to the previous behavior by setting GO111MODULE to auto, but we do not want to do that—modules are the future. The reason for mentioning this in this chapter is that both viper and cobra prefer to be treated as Go modules instead of packages, which changes the development process but not the code.

Topics to cover

This chapter covers:

  • stdin, stdout, and stderr

  • UNIX processes

  • Handling UNIX signals

  • File input and output

  • Reading plain text files

  • Writing to a file

  • Working with JSON

  • Working with XML

  • Working with YAML

  • The viper package

  • The cobra package

  • Finding cycles in a UNIX file system

  • New features in Go 1.16

  • Updating the phone book application

Get hands-on with 1200+ tech skills courses.