An advanced example of the context package

The functionality of the context package will be illustrated much better and in greater depth using the Go code of the useContext.go program, which is presented in five parts.

In this example, you will create an HTTP client that does not want to wait too long for a server response, which is not an unusual scenario. In fact, as almost all HTTP clients support such functionality, you will study another technique for timing out an HTTP request in Chapter 12, The Foundations of Network Programming in Go.

The useContext.go program requires two command-line arguments: the URL of the server to which it is going to connect and the delay for which it should wait. If the program has only one command-line argument, ...

Get Mastering Go now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.