Introduction of cache interface and a file cacher.

This commit is contained in:
Burcu Dogan
2014-05-19 00:14:56 +02:00
parent 643fd905db
commit 227bfbf02f
3 changed files with 72 additions and 0 deletions

View File

@@ -74,6 +74,7 @@ type TokenFetcher interface {
// If the implementation doesn't know how to retrieve a new token,
// it returns an error.
FetchToken(existing *Token) (*Token, error)
Cache() Cache
}
// Options represents options to provide OAuth 2.0 client credentials
@@ -138,6 +139,8 @@ type Config struct {
authURL string
// TokenURL is the URL used to retrieve OAuth tokens.
tokenURL string
cache Cache
}
// Options returns options.
@@ -224,6 +227,11 @@ func (c *Config) FetchToken(existing *Token) (*Token, error) {
return existing, err
}
// Cache returns a cache if specified, otherwise nil.
func (c *Config) Cache() Cache {
return c.cache
}
// Checks if all required configuration fields have non-zero values.
func (c *Config) validate() error {
if c.opts.ClientID == "" {