master
1package main
2
3import (
4 "fmt"
5 "io/ioutil"
6 "net/http"
7 "os"
8 "time"
9)
10
11// curl -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/search/issues?q=" | jq .items[].title | sort
12
13func main() {
14
15 token := os.Getenv("GITHUB_TOKEN")
16 url := "https://api.github.com/search/issues"
17 accept := "application/vnd.github.v3+json"
18 auth := fmt.Sprintf("token %s", token)
19 search := "repo:alta3/labs+state:open"
20
21 c := http.Client{Timeout: time.Duration(1) * time.Second}
22 req, err := http.NewRequest("GET", url, nil)
23 if err != nil {
24 fmt.Printf("Error %s", err)
25 return
26 }
27 req.Header.Set("Authorization", auth)
28 req.Header.Set("Accept", accept)
29
30 q := req.URL.Query()
31 q.Add("q", search)
32 q.Add("page", "1")
33 q.Add("per_page", "100")
34 req.URL.RawQuery = q.Encode()
35 fmt.Println(req.URL)
36
37 resp, err := c.Do(req)
38 if err != nil {
39 fmt.Printf("Error %s", err)
40 return
41 }
42 defer resp.Body.Close()
43 body, err := ioutil.ReadAll(resp.Body)
44 fmt.Printf("Body : %s", body)
45}