How it works...

This code demonstrates how to hide logic such as authentication, and performing a token refresh using the Transport interface. It also demonstrates how to expose an API call via a method. Had we been implementing against something such as a user API, we would expect methods such as the following:

type API interface{
GetUsers() (Users, error)
CreateUser(User) error
UpdateUser(User) error
DeleteUser(User)
}

If you've read Chapter 5, All about Databases and Storage, this may look similar to the recipe entitled Executing a database transaction interface. This composition through interfaces, especially common interfaces such as the RoundTripper interface, provides a lot of flexibility for writing APIs. In addition, it may be useful to write a top-level interface as we did earlier and pass the interface around instead of to the client directly. We'll explore this in more detail in the next recipe as we explore writing an OAuth2 client.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.196.27