This section will present a technique for timing out network connections that take too long to finish. Remember that you already know such a technique from Chapter 10, Concurrency in Go – Advanced Topics, when we talked about the context standard Go package. This technique was presented in the useContext.go source code file.
The method that is going to be presented in this section is much easier to implement. The relevant code is saved in clientTimeOut.go and it is going to be presented in four parts. The utility accepts two command-line arguments, which are the URL and the timeout period in seconds. Please notice that the second parameter is optional.
The first part of the code portion for clientTimeOut.go is as follows:
package main import ( "fmt" "io" "net" "net/http" "...