Skip to content

Commit 4a23999

Browse files
committed
Update documentation with new context parameter.
ctx is a common and well understood variable name that represents the current context.Context value. This is a followup to #529.
1 parent 654d25d commit 4a23999

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ access different parts of the GitHub API. For example:
2222
client := github.NewClient(nil)
2323

2424
// list all organizations for user "willnorris"
25-
orgs, _, err := client.Organizations.List("willnorris", nil)
25+
orgs, _, err := client.Organizations.List(ctx, "willnorris", nil)
2626
```
2727

2828
Some API methods have optional parameters that can be passed. For example:
@@ -32,7 +32,7 @@ client := github.NewClient(nil)
3232

3333
// list public repositories for org "github"
3434
opt := &github.RepositoryListByOrgOptions{Type: "public"}
35-
repos, _, err := client.Repositories.ListByOrg("github", opt)
35+
repos, _, err := client.Repositories.ListByOrg(ctx, "github", opt)
3636
```
3737

3838
The services of a client divide the API into logical chunks and correspond to
@@ -60,7 +60,7 @@ func main() {
6060
client := github.NewClient(tc)
6161

6262
// list all repositories for the authenticated user
63-
repos, _, err := client.Repositories.List("", nil)
63+
repos, _, err := client.Repositories.List(ctx, "", nil)
6464
}
6565
```
6666

@@ -90,7 +90,7 @@ up-to-date rate limit data for the client.
9090
To detect an API rate limit error, you can check if its type is `*github.RateLimitError`:
9191

9292
```go
93-
repos, _, err := client.Repositories.List("", nil)
93+
repos, _, err := client.Repositories.List(ctx, "", nil)
9494
if _, ok := err.(*github.RateLimitError); ok {
9595
log.Println("hit rate limit")
9696
}
@@ -110,7 +110,7 @@ To detect this condition of error, you can check if its type is
110110
`*github.AcceptedError`:
111111

112112
```go
113-
stats, _, err := client.Repositories.ListContributorsStats(org, repo)
113+
stats, _, err := client.Repositories.ListContributorsStats(ctx, org, repo)
114114
if _, ok := err.(*github.AcceptedError); ok {
115115
log.Println("scheduled on GitHub side")
116116
}
@@ -140,7 +140,7 @@ repo := &github.Repository{
140140
Name: github.String("foo"),
141141
Private: github.Bool(true),
142142
}
143-
client.Repositories.Create("", repo)
143+
client.Repositories.Create(ctx, "", repo)
144144
```
145145

146146
Users who have worked with protocol buffers should find this pattern familiar.
@@ -163,7 +163,7 @@ opt := &github.RepositoryListByOrgOptions{
163163
// get all pages of results
164164
var allRepos []*github.Repository
165165
for {
166-
repos, resp, err := client.Repositories.ListByOrg("github", opt)
166+
repos, resp, err := client.Repositories.ListByOrg(ctx, "github", opt)
167167
if err != nil {
168168
return err
169169
}

github/doc.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ access different parts of the GitHub API. For example:
1616
client := github.NewClient(nil)
1717
1818
// list all organizations for user "willnorris"
19-
orgs, _, err := client.Organizations.List("willnorris", nil)
19+
orgs, _, err := client.Organizations.List(ctx, "willnorris", nil)
2020
2121
Some API methods have optional parameters that can be passed. For example:
2222
2323
client := github.NewClient(nil)
2424
2525
// list public repositories for org "github"
2626
opt := &github.RepositoryListByOrgOptions{Type: "public"}
27-
repos, _, err := client.Repositories.ListByOrg("github", opt)
27+
repos, _, err := client.Repositories.ListByOrg(ctx, "github", opt)
2828
2929
The services of a client divide the API into logical chunks and correspond to
3030
the structure of the GitHub API documentation at
@@ -50,7 +50,7 @@ use it with the oauth2 library using:
5050
client := github.NewClient(tc)
5151
5252
// list all repositories for the authenticated user
53-
repos, _, err := client.Repositories.List("", nil)
53+
repos, _, err := client.Repositories.List(ctx, "", nil)
5454
}
5555
5656
Note that when using an authenticated Client, all calls made by the client will
@@ -78,7 +78,7 @@ up-to-date rate limit data for the client.
7878
7979
To detect an API rate limit error, you can check if its type is *github.RateLimitError:
8080
81-
repos, _, err := client.Repositories.List("", nil)
81+
repos, _, err := client.Repositories.List(ctx, "", nil)
8282
if _, ok := err.(*github.RateLimitError); ok {
8383
log.Println("hit rate limit")
8484
}
@@ -96,7 +96,7 @@ this behavior.
9696
To detect this condition of error, you can check if its type is
9797
*github.AcceptedError:
9898
99-
stats, _, err := client.Repositories.ListContributorsStats(org, repo)
99+
stats, _, err := client.Repositories.ListContributorsStats(ctx, org, repo)
100100
if _, ok := err.(*github.AcceptedError); ok {
101101
log.Println("scheduled on GitHub side")
102102
}
@@ -124,7 +124,7 @@ bool, and int values. For example:
124124
Name: github.String("foo"),
125125
Private: github.Bool(true),
126126
}
127-
client.Repositories.Create("", repo)
127+
client.Repositories.Create(ctx, "", repo)
128128
129129
Users who have worked with protocol buffers should find this pattern familiar.
130130
@@ -145,7 +145,7 @@ github.Response struct.
145145
// get all pages of results
146146
var allRepos []*github.Repository
147147
for {
148-
repos, resp, err := client.Repositories.ListByOrg("github", opt)
148+
repos, resp, err := client.Repositories.ListByOrg(ctx, "github", opt)
149149
if err != nil {
150150
return err
151151
}

0 commit comments

Comments
 (0)