Book Image

Go Systems Programming

Book Image

Go Systems Programming

Overview of this book

Go is the new systems programming language for Linux and Unix systems. It is also the language in which some of the most prominent cloud-level systems have been written, such as Docker. Where C programmers used to rule, Go programmers are in demand to write highly optimized systems programming code. Created by some of the original designers of C and Unix, Go expands the systems programmers toolkit and adds a mature, clear programming language. Traditional system applications become easier to write since pointers are not relevant and garbage collection has taken away the most problematic area for low-level systems code: memory management. This book opens up the world of high-performance Unix system applications to the beginning Go programmer. It does not get stuck on single systems or even system types, but tries to expand the original teachings from Unix system level programming to all types of servers, the cloud, and the web.
Table of Contents (13 chapters)

The select keyword

A select statement in Go is like a switch statement for channels and allows a goroutine to wait on multiple communication operations. Therefore, the main advantage you get from using the select keyword is that the same function can deal with multiple channels using a single select statement! Additionally, you can have nonblocking operations on channels.

The name of the program that will be used for illustrating the select keyword will be useSelect.go and will be presented in five parts. The useSelect.go program allows you to generate the number of random you want, which is defined in the first command-line argument, up to a certain limit, which is the second command-line argument.

The first part of useSelect.go is the following:

package main 
 
import ( 
   "fmt" 
   "math/rand" 
   "os" 
   "path/filepath" 
   "strconv...