Initializing, storing, and passing http.Client structs
The Go net/http package exposes a flexible http.Client struct for working with HTTP APIs. This struct has separate transport functionality and is relatively simple to short-circuit requests, modify headers for each client operation, and handle any REST operations. Creating clients is a very common operation, and this recipe will start with the basics of working and creating an http.Client object.
Getting ready
Configure your environment according to these steps:
- Download and install Go on your operating system from https://golang.org/doc/install and configure your
GOPATHenvironment variable. - Open a terminal/console application.
- Navigate to
GOPATH/srcand create a project directory. For example,$GOPATH/src/github.com/yourusername/customrepo.
All code will be run and modified from this directory.
- Optionally, install the latest tested version of the code using the
go get github.com/agtorre/go-cookbook/command.
How to do it...
These steps cover...