November 2017
Intermediate to advanced
670 pages
17h 35m
English
Our first decorator is Authorization. We call the Header helper function that adds the Authorization header with the given token to each request at runtime:
func Authorization(token string) Decorator { return Header("Authorization", token)}func Header(name, value string) Decorator { return func(c Client) Client { return ClientFunc(func(r *http.Request)(*http.Response, error) { r.Header.Add(name, value) return c.Do(r) }) }}