Return errors on nil credentials, move code around

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian
2020-08-27 00:29:53 -04:00
parent c0f0cf8be6
commit c4faa00b94
6 changed files with 110 additions and 104 deletions
+3 -11
View File
@@ -51,16 +51,8 @@ func (s *oauthTokenSource) Token() (*oauth2.Token, error) {
}
func oauthTransport(client *Client) http.RoundTripper {
// We need to set a custom user agent, because using the one set by default by the
// stdlib gives us 429 Too Many Request responses from the Reddit API.
userAgentTransport := &userAgentTransport{
userAgent: client.UserAgent(),
Base: client.client.Transport,
}
httpClient := &http.Client{Transport: userAgentTransport}
ctx := context.Background()
ctx = context.WithValue(ctx, oauth2.HTTPClient, httpClient)
httpClient := &http.Client{Transport: client.client.Transport}
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, httpClient)
config := &oauth2.Config{
ClientID: client.ID,
@@ -80,6 +72,6 @@ func oauthTransport(client *Client) http.RoundTripper {
return &oauth2.Transport{
Source: tokenSource,
Base: userAgentTransport,
Base: client.client.Transport,
}
}