-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
45 lines (37 loc) · 866 Bytes
/
main.go
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
package main
import (
"context"
"log"
"os"
"github.com/machinebox/graphql"
)
// Response of APi
type Response struct {
License struct {
Name string `json:"name"`
Description string `json:"description"`
} `json:"license"`
}
func main() {
// create a client (safe to share across requests)
client := graphql.NewClient("https://api.github.com/graphql")
// make a request to GitHub API
req := graphql.NewRequest(`
query {
license(key: "apache-2.0") {
name
description
}
}
`)
var GithubToken = os.Getenv("GITHUB_TOKEN")
req.Header.Add("Authorization", "bearer "+GithubToken)
// define a Context for the request
ctx := context.Background()
// run it and capture the response
var respData Response
if err := client.Run(ctx, req, &respData); err != nil {
log.Fatal(err)
}
log.Println(respData.License.Description)
}