-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry.go
66 lines (57 loc) · 1.46 KB
/
entry.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
"github.com/mhassaninmsft/gogitcrawler/util"
)
type Contributor struct {
Login string `json:"login"`
}
// import ("github.com/mhassaninmsft/gogitcrawler/util" "")
func main_old() {
println("Hello, World!")
var x = util.AddTwo(1, 2)
println(x)
// if len(os.Args) < 2 {
// fmt.Println("Usage: go run main.go <repository>")
// os.Exit(1)
// }
// repo := os.Args[1]
GITHUB_TOKEN, found := os.LookupEnv("GITHUB_TOKEN")
if !found {
fmt.Println("GITHUB_TOKEN environment variable not found")
os.Exit(1)
}
url := "https://api.github.com/repos/google/material-design-icons/contributors"
authorization_token := fmt.Sprintf("Bearer %s", GITHUB_TOKEN)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
fmt.Println("Error creating request:", err)
os.Exit(1)
}
req.Header.Set("Accept", "application/vnd.github+json")
req.Header.Set("X-GitHub-Api-Version", "2022-11-28")
req.Header.Set("Authorization", authorization_token)
client := http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error sending request:", err)
os.Exit(1)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
fmt.Println("Error:", resp.Status)
os.Exit(1)
}
var contributors []Contributor
err = json.NewDecoder(resp.Body).Decode(&contributors)
if err != nil {
fmt.Println("Error decoding response:", err)
os.Exit(1)
}
for _, c := range contributors {
fmt.Println(c.Login)
}
}