From 4b558944a3f97b921526de818160b17c2be2b409 Mon Sep 17 00:00:00 2001 From: Burcu Dogan Date: Mon, 26 May 2014 16:47:46 +0200 Subject: [PATCH] Provide missing docs for Cache interface and transport constructors. --- cache.go | 7 ++++--- jwt.go | 3 +++ oauth2.go | 3 +++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cache.go b/cache.go index 16653e2..72752be 100644 --- a/cache.go +++ b/cache.go @@ -12,10 +12,9 @@ import ( // Cache represents a token cacher. type Cache interface { - // Reads a cached token. - // It may return a nil value if no token is cached. + // Reads a cached token. It may return nil if none is cached. Read() (token *Token, err error) - // Write writes a token to the specified file. + // Write writes a token to the cache. Write(token *Token) } @@ -32,6 +31,8 @@ type FileCache struct { filename string } +// Read reads the token from the cache file. If there exists no cache +// file, it returns nil for the token. func (f *FileCache) Read() (token *Token, err error) { data, err := ioutil.ReadFile(f.filename) if os.IsNotExist(err) { diff --git a/jwt.go b/jwt.go index b225d19..0af6946 100644 --- a/jwt.go +++ b/jwt.go @@ -76,6 +76,9 @@ func (c *JWTConfig) NewTransportWithUser(user string) Transport { return NewAuthorizedTransport(c, &Token{Subject: user}) } +// NewTransportWithCache initializes a transport by reading the initial +// token from the provided cache. If a token refreshing occurs, it +// writes the newly fetched token back to the cache. func (c *JWTConfig) NewTransportWithCache(cache Cache) (Transport, error) { token, err := cache.Read() if err != nil { diff --git a/oauth2.go b/oauth2.go index 62187d5..50b1517 100644 --- a/oauth2.go +++ b/oauth2.go @@ -188,6 +188,9 @@ func (c *Config) NewTransportWithCode(exchangeCode string) (Transport, error) { return NewAuthorizedTransport(c, token), nil } +// NewTransportWithCache initializes a transport by reading the initial +// token from the provided cache. If a token refreshing occurs, it +// writes the newly fetched token back to the cache. func (c *Config) NewTransportWithCache(cache Cache) (Transport, error) { token, err := cache.Read() if err != nil {