June 2017
Intermediate to advanced
400 pages
10h 32m
English
The net/http package exposes a DefaultClient package variable, which is used by the internal operations, Do, GET, POST, and so on. Our Setup() function returns a client and sets the default client to be the same. When setting up a client, most of your modifications will take place in the transport, which only needs to implement the RoundTripper interface.
This recipe gives an example of a no-op round tripper that always returns a 418 status code. You can imagine how this might be useful for testing. It also demonstrates passing in clients as function arguments, using them as struct parameters, and using the default client to process requests.
Read now
Unlock full access