Debian Codegraph @

example/ratelimit/main.go

raw
1 // Copyright 2023 The go-github AUTHORS. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file.
5
6 // The ratelimit command demonstrates using the github_ratelimit.SecondaryRateLimitWaiter.
7 // By using the waiter, the client automatically sleeps and retry requests
8 // when it hits secondary rate limits.
9 package main
10
11 import (
12 "context"
13 "fmt"
14
15 "github.com/gofri/go-github-ratelimit/github_ratelimit"
16 "github.com/google/go-github/v60/github"
17 )
18
19 func main() {
20 var username string
21 fmt.Print("Enter GitHub username: ")
22 fmt.Scanf("%s", &username)
23
24 rateLimiter, err := github_ratelimit.NewRateLimitWaiterClient(nil)
25 if err != nil {
26 fmt.Printf("Error: %v\n", err)
27 return
28 }
29
30 client := github.NewClient(rateLimiter)
31
32 // arbitrary usage of the client
33 organizations, _, err := client.Organizations.List(context.Background(), username, nil)
34 if err != nil {
35 fmt.Printf("Error: %v\n", err)
36 return
37 }
38
39 for i, organization := range organizations {
40 fmt.Printf("%v. %v\n", i+1, organization.GetLogin())
41 }
42 }