@@ -16,15 +16,15 @@ access different parts of the GitHub API. For example:
16
16
client := github.NewClient(nil)
17
17
18
18
// list all organizations for user "willnorris"
19
- orgs, _, err := client.Organizations.List("willnorris", nil)
19
+ orgs, _, err := client.Organizations.List(ctx, "willnorris", nil)
20
20
21
21
Some API methods have optional parameters that can be passed. For example:
22
22
23
23
client := github.NewClient(nil)
24
24
25
25
// list public repositories for org "github"
26
26
opt := &github.RepositoryListByOrgOptions{Type: "public"}
27
- repos, _, err := client.Repositories.ListByOrg("github", opt)
27
+ repos, _, err := client.Repositories.ListByOrg(ctx, "github", opt)
28
28
29
29
The services of a client divide the API into logical chunks and correspond to
30
30
the structure of the GitHub API documentation at
@@ -50,7 +50,7 @@ use it with the oauth2 library using:
50
50
client := github.NewClient(tc)
51
51
52
52
// list all repositories for the authenticated user
53
- repos, _, err := client.Repositories.List("", nil)
53
+ repos, _, err := client.Repositories.List(ctx, "", nil)
54
54
}
55
55
56
56
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.
78
78
79
79
To detect an API rate limit error, you can check if its type is *github.RateLimitError:
80
80
81
- repos, _, err := client.Repositories.List("", nil)
81
+ repos, _, err := client.Repositories.List(ctx, "", nil)
82
82
if _, ok := err.(*github.RateLimitError); ok {
83
83
log.Println("hit rate limit")
84
84
}
@@ -96,7 +96,7 @@ this behavior.
96
96
To detect this condition of error, you can check if its type is
97
97
*github.AcceptedError:
98
98
99
- stats, _, err := client.Repositories.ListContributorsStats(org, repo)
99
+ stats, _, err := client.Repositories.ListContributorsStats(ctx, org, repo)
100
100
if _, ok := err.(*github.AcceptedError); ok {
101
101
log.Println("scheduled on GitHub side")
102
102
}
@@ -124,7 +124,7 @@ bool, and int values. For example:
124
124
Name: github.String("foo"),
125
125
Private: github.Bool(true),
126
126
}
127
- client.Repositories.Create("", repo)
127
+ client.Repositories.Create(ctx, "", repo)
128
128
129
129
Users who have worked with protocol buffers should find this pattern familiar.
130
130
@@ -145,7 +145,7 @@ github.Response struct.
145
145
// get all pages of results
146
146
var allRepos []*github.Repository
147
147
for {
148
- repos, resp, err := client.Repositories.ListByOrg("github", opt)
148
+ repos, resp, err := client.Repositories.ListByOrg(ctx, "github", opt)
149
149
if err != nil {
150
150
return err
151
151
}
0 commit comments