From 99146a08aadebd4d1cca2b9f3cb8a58034084d20 Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Wed, 31 May 2023 10:48:56 +0800 Subject: [PATCH] oauth2.NoContext deprecated and unnecessary use of fmt.Sprintf --- google/example_test.go | 12 ++++++------ oauth2_test.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/google/example_test.go b/google/example_test.go index 3fc9cad3f..f094bfc00 100644 --- a/google/example_test.go +++ b/google/example_test.go @@ -17,7 +17,7 @@ import ( ) func ExampleDefaultClient() { - client, err := google.DefaultClient(oauth2.NoContext, + client, err := google.DefaultClient(context.Background(), "https://www.googleapis.com/auth/devstorage.full_control") if err != nil { log.Fatal(err) @@ -44,11 +44,11 @@ func Example_webServer() { fmt.Printf("Visit the URL for the auth dialog: %v", url) // Handle the exchange code to initiate a transport. - tok, err := conf.Exchange(oauth2.NoContext, "authorization-code") + tok, err := conf.Exchange(context.Background(), "authorization-code") if err != nil { log.Fatal(err) } - client := conf.Client(oauth2.NoContext, tok) + client := conf.Client(context.Background(), tok) client.Get("...") } @@ -71,7 +71,7 @@ func ExampleJWTConfigFromJSON() { // Initiate an http.Client. The following GET request will be // authorized and authenticated on the behalf of // your service account. - client := conf.Client(oauth2.NoContext) + client := conf.Client(context.Background()) client.Get("...") } @@ -84,7 +84,7 @@ func ExampleSDKConfig() { } // Initiate an http.Client. The following GET request will be // authorized and authenticated on the behalf of the SDK user. - client := conf.Client(oauth2.NoContext) + client := conf.Client(context.Background()) client.Get("...") } @@ -116,7 +116,7 @@ func Example_serviceAccount() { } // Initiate an http.Client, the following GET request will be // authorized and authenticated on the behalf of user@example.com. - client := conf.Client(oauth2.NoContext) + client := conf.Client(context.Background()) client.Get("...") } diff --git a/oauth2_test.go b/oauth2_test.go index a3517767d..62e6207f2 100644 --- a/oauth2_test.go +++ b/oauth2_test.go @@ -282,7 +282,7 @@ func TestExchangeRequest_JSONResponse_Expiry(t *testing.T) { }{ {"normal", fmt.Sprintf(`"expires_in": %d`, seconds), true, false}, {"paypal", fmt.Sprintf(`"expires_in": "%d"`, seconds), true, false}, - {"issue_239", fmt.Sprintf(`"expires_in": null`), true, true}, + {"issue_239", `"expires_in": null`, true, true}, {"wrong_type", `"expires_in": false`, false, false}, {"wrong_type2", `"expires_in": {}`, false, false},