June 2017
Intermediate to advanced
400 pages
10h 32m
English
This recipe takes advantage of closures as first-class citizens and interfaces. The main trick that allows for this is having a function implement an interface. This allows us to wrap an interface implemented by a structure with an interface implemented by a function.
The middleware.go file contains two example client middleware functions. These could be extended to contain additional middleware, such as more sophisticated auth, metrics, and more. This recipe can also be combined with the previous recipe to produce an OAuth2 client that can be extended by additional middleware.
The Decorator function is a convenience function that allows the following:
Decorate(RoundTripper, Middleware1, Middleware2, etc)vsvar t RoundTripper ...
Read now
Unlock full access