From 9eb187bac4eba6fff5a54f80550b2df73b651523 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Mon, 11 May 2015 14:35:14 -0700 Subject: [PATCH] oauth2 package now provides a StaticTokenSource --- README.md | 15 ++------------- github/doc.go | 15 ++------------- tests/fields/fields.go | 14 ++------------ tests/integration/github_test.go | 14 ++------------ 4 files changed, 8 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index c344d2e..dbf32c5 100644 --- a/README.md +++ b/README.md @@ -43,21 +43,10 @@ library, but you can always use any other library that provides an API token][]), you can use it with oauth2 using: ```go -// tokenSource is an oauth2.TokenSource which returns a static access token -type tokenSource struct { - token *oauth2.Token -} - -// Token implements the oauth2.TokenSource interface -func (t *tokenSource) Token() (*oauth2.Token, error){ - return t.token, nil -} - func main() { - ts := &tokenSource{ + ts := oauth2.StaticTokenSource( &oauth2.Token{AccessToken: "... your access token ..."}, - } - + ) tc := oauth2.NewClient(oauth2.NoContext, ts) client := github.NewClient(tc) diff --git a/github/doc.go b/github/doc.go index 9e48242..b4ac8e6 100644 --- a/github/doc.go +++ b/github/doc.go @@ -35,21 +35,10 @@ use it with the oauth2 library using: import "golang.org/x/oauth2" - // tokenSource is an oauth2.TokenSource which returns a static access token - type tokenSource struct { - token *oauth2.Token - } - - // Token implements the oauth2.TokenSource interface - func (t *tokenSource) Token() (*oauth2.Token, error){ - return t.token, nil - } - func main() { - ts := &tokenSource{ + ts := oauth2.StaticTokenSource( &oauth2.Token{AccessToken: "... your access token ..."}, - } - + ) tc := oauth2.NewClient(oauth2.NoContext, ts) client := github.NewClient(tc) diff --git a/tests/fields/fields.go b/tests/fields/fields.go index 67e4050..1228bf8 100644 --- a/tests/fields/fields.go +++ b/tests/fields/fields.go @@ -38,16 +38,6 @@ var ( skipURLs = flag.Bool("skip_urls", false, "skip url fields") ) -// tokenSource is an oauth2.TokenSource which returns a static access token -type tokenSource struct { - token *oauth2.Token -} - -// Token implements the oauth2.TokenSource interface -func (t *tokenSource) Token() (*oauth2.Token, error) { - return t.token, nil -} - func main() { flag.Parse() @@ -56,9 +46,9 @@ func main() { print("!!! No OAuth token. Some tests won't run. !!!\n\n") client = github.NewClient(nil) } else { - tc := oauth2.NewClient(oauth2.NoContext, &tokenSource{ + tc := oauth2.NewClient(oauth2.NoContext, oauth2.StaticTokenSource( &oauth2.Token{AccessToken: token}, - }) + )) client = github.NewClient(tc) auth = true } diff --git a/tests/integration/github_test.go b/tests/integration/github_test.go index 14376b9..328f1e5 100644 --- a/tests/integration/github_test.go +++ b/tests/integration/github_test.go @@ -25,25 +25,15 @@ var ( auth bool ) -// tokenSource is an oauth2.TokenSource which returns a static access token -type tokenSource struct { - token *oauth2.Token -} - -// Token implements the oauth2.TokenSource interface -func (t *tokenSource) Token() (*oauth2.Token, error) { - return t.token, nil -} - func init() { token := os.Getenv("GITHUB_AUTH_TOKEN") if token == "" { print("!!! No OAuth token. Some tests won't run. !!!\n\n") client = github.NewClient(nil) } else { - tc := oauth2.NewClient(oauth2.NoContext, &tokenSource{ + tc := oauth2.NewClient(oauth2.NoContext, oauth2.StaticTokenSource( &oauth2.Token{AccessToken: token}, - }) + )) client = github.NewClient(tc) auth = true }