Fixing styling issues for caching.

This commit is contained in:
Burcu Dogan
2014-05-22 14:33:36 +02:00
parent 0476447419
commit 6bb3577bf0
3 changed files with 18 additions and 14 deletions

View File

@@ -94,12 +94,14 @@ func NewAuthorizedTransport(fetcher TokenFetcher, token *Token) Transport {
// If token is expired, tries to refresh/fetch a new token.
func (t *authorizedTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
token := t.Token()
cache := t.fetcher.Cache()
if token == nil && cache != nil {
// Try to read from cache initially
token = cache.Read()
// Try to initialize the token from the cache.
if token == nil {
if c := t.fetcher.Cache(); c != nil {
token = c.Read()
}
}
if token == nil || token.Expired() {
// Check if the token is refreshable.
// If token is refreshable, don't return an error,
@@ -165,9 +167,8 @@ func (t *authorizedTransport) RefreshToken() error {
}
t.token = token
cache := t.fetcher.Cache()
if cache != nil {
cache.Write(token)
if c := t.fetcher.Cache(); c != nil {
c.Write(token)
}
return nil