-
Notifications
You must be signed in to change notification settings - Fork 0
/
stars.go
67 lines (57 loc) · 1.18 KB
/
stars.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
67
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"time"
dotenv "github.com/joho/godotenv"
)
func handle(err error) {
if err != nil {
panic(err)
}
}
// TODO: Replace [starred](https://github.com/maguowei/starred) with custom
func main() {
err := dotenv.Load()
handle(err)
client := http.Client{
Timeout: time.Second * 10,
}
req, err := http.NewRequest("GET", "https://api.github.com/users/hyperupcall/starred", nil)
handle(err)
env, hasToken := os.LookupEnv("GITHUB_TOKEN")
if hasToken {
req.Header.Add("Authorization", "token "+env)
}
res, err := client.Do(req)
handle(err)
defer res.Body.Close()
content, err := ioutil.ReadAll(res.Body)
handle(err)
type Repo struct {
name string
full_name string
description string
fork bool
url string
size int
stargazers_count int
watchers_count int
language string
forks_count string
license struct {
key string
name string
spdx_id string
url string
}
topics []string
}
var repos []Repo
err = json.Unmarshal(content, &repos)
handle(err)
fmt.Printf("%+v", repos)
}