
上QQ阅读APP看书,第一时间看更新
Authorization decorator
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)
})
}
}