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
|
package githubv4_test
import (
"context"
"fmt"
"log"
"os"
"time"
"github.com/shurcooL/githubv4"
"golang.org/x/oauth2"
)
func Example() {
src := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")},
)
httpClient := oauth2.NewClient(context.Background(), src)
client := githubv4.NewClient(httpClient)
var q struct {
Viewer struct {
Login string
CreatedAt time.Time
AvatarURL string `graphql:"avatarUrl(size: 72)"`
}
}
err := client.Query(context.Background(), &q, nil)
if err != nil {
log.Fatalln(err)
}
fmt.Println(q.Viewer.Login)
fmt.Println(q.Viewer.CreatedAt)
fmt.Println(q.Viewer.AvatarURL)
}
|