Skip to content

Commit ed4cdce

Browse files
committed
examples/basicauth: Use a single program-scoped context.
Having a program that makes one or two requests in main is a little unusual, but using a single program-scoped context makes more sense and sets a better example.
1 parent 6b55015 commit ed4cdce

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎examples/basicauth/main.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ func main() {
3535
}
3636

3737
client := github.NewClient(tp.Client())
38-
user, _, err := client.Users.Get(context.Background(), "")
38+
ctx := context.Background()
39+
user, _, err := client.Users.Get(ctx, "")
3940

4041
// Is this a two-factor auth error? If so, prompt for OTP and try again.
4142
if _, ok := err.(*github.TwoFactorAuthError); err != nil && ok {
4243
fmt.Print("\nGitHub OTP: ")
4344
otp, _ := r.ReadString('\n')
4445
tp.OTP = strings.TrimSpace(otp)
45-
user, _, err = client.Users.Get(context.Background(), "")
46+
user, _, err = client.Users.Get(ctx, "")
4647
}
4748

4849
if err != nil {

0 commit comments

Comments
 (0)