In this section, you will learn more about developing web clients in Go. The name of the web client utility is webClient.go, and it is going to be presented in four parts.
The first part of webClient.go contains the following Go code:
package main import ( "fmt" "io" "net/http" "os" "path/filepath" )
The second part of webClient.go is where you read the desired URL as a command-line argument:
func main() { if len(os.Args) != 2 { fmt.Printf("Usage: %s URL\n", filepath.Base(os.Args[0])) return } URL := os.Args[1]
The third code portion of webClient.go is where the real action takes place:
data, err := http.Get(URL) if err != nil { fmt.Println(err) return
All of the work is done by the http.Get() call...