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)

A handy command-line utility

In this section, we will develop a handy command-line utility that reads a number of web pages, which can be found in a text file or read from standard input, and returns the number of times a given keyword was found in these web pages. In order to be faster, the utility will use goroutines to get the desired data and a monitoring process to gather the data and present it on the screen. The name of the utility will be findKeyword.go and will be presented in five parts.

The first part of the utility is the following:

package main 
 
import ( 
   "bufio" 
   "fmt" 
   "net/http" 
   "net/url" 
   "os" 
   "regexp" 
) 
 
type Data struct { 
   URL     string 
   Keyword string 
   Times   int 
   Error   error 
} 

The Data struct type will be used for passing information between channels.

The...