Making your Go web client more advanced

As the web client of the previous section is relatively simplistic and does not give you any flexibility, in this section, you will learn how to read a URL more elegantly without using the http.Get() function, and with more options. The name of the utility is advancedWebClient.go and it is going to be presented in five parts.

The first code segment of advancedWebClient.go contains the following Go code:

package main 
 
import ( 
    "fmt" 
    "net/http" 
    "net/http/httputil" 
    "net/url" 
    "os" 
    "path/filepath" 
    "strings" 
    "time" 
) 

The second part of advancedWebClient.go is as follows:

func main() { if len(os.Args) != 2 { fmt.Printf("Usage: %s URL\n", filepath.Base(os.Args[0])) return } URL, err := url.Parse(os.Args[1]) ...

Get Mastering Go - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.