...
1 package githubv4_test
2
3 import (
4 "context"
5 "fmt"
6 "log"
7 "os"
8 "time"
9
10 "github.com/shurcooL/githubv4"
11 "golang.org/x/oauth2"
12 )
13
14 func Example() {
15 src := oauth2.StaticTokenSource(
16 &oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")},
17 )
18 httpClient := oauth2.NewClient(context.Background(), src)
19
20 client := githubv4.NewClient(httpClient)
21
22 var q struct {
23 Viewer struct {
24 Login string
25 CreatedAt time.Time
26 AvatarURL string `graphql:"avatarUrl(size: 72)"`
27 }
28 }
29 err := client.Query(context.Background(), &q, nil)
30 if err != nil {
31 log.Fatalln(err)
32 }
33 fmt.Println(q.Viewer.Login)
34 fmt.Println(q.Viewer.CreatedAt)
35 fmt.Println(q.Viewer.AvatarURL)
36 }
37
View as plain text