-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
54 lines (42 loc) · 1.27 KB
/
Copy pathmain.go
File metadata and controls
54 lines (42 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"context"
"fmt"
"net/http"
"github.com/Khan/genqlient/graphql"
"github.com/alexhwoods/evaluate-genqlient/generated"
)
//go:generate go run github.com/Khan/genqlient genqlient.yaml
const GithubGraphqlAPI = "https://api.github.com/graphql"
type authedTransport struct {
key string
wrapped http.RoundTripper
}
func (t *authedTransport) RoundTrip(req *http.Request) (*http.Response, error) {
if req.URL.String() == GithubGraphqlAPI {
req.Header.Set("Authorization", "Bearer "+t.key)
}
return t.wrapped.RoundTrip(req)
}
func main() {
key := "<personal-access-token>"
ctx := context.Background()
httpClient := http.Client{
Transport: &authedTransport{
key: key,
wrapped: http.DefaultTransport,
},
}
client := graphql.NewClient(GithubGraphqlAPI, &httpClient)
resp, err := generated.GetRepository(ctx, client, "kubernetes", "kubernetes")
if err != nil {
fmt.Printf("error: %s", err)
}
useRepository(resp.Repository)
}
func useRepository(repository generated.GetRepositoryRepository) {
fmt.Printf("repository.Name: %v\n", repository.Name)
fmt.Printf("repository.Description: %v\n", repository.Description)
fmt.Printf("repository.StargazerCount: %v\n", repository.StargazerCount)
fmt.Printf("repository.Url: %v\n", repository.Url)
}