|
1 | 1 | package main |
2 | 2 |
|
3 | | -import ( |
4 | | - "encoding/json" |
5 | | - "github.com/sirupsen/logrus" |
6 | | - "io" |
7 | | - "net/http" |
8 | | -) |
| 3 | +import "fmt" |
9 | 4 |
|
10 | | -func Get(uri string) (res map[string]interface{}, err error) { |
11 | | - req, err := http.NewRequest("GET", "https://api.github.com/"+uri, nil) |
12 | | - if err != nil { |
13 | | - return nil, err |
14 | | - } |
15 | | - |
16 | | - req.Header.Set("Accept", "application/json") |
17 | | - req.Header.Set("Authorization", "Bearer "+GetToken()) |
| 5 | +func GetUser(username string) (res map[string]interface{}, err error) { |
| 6 | + return Get(fmt.Sprintf("users/%s", username)) |
| 7 | +} |
18 | 8 |
|
19 | | - client := &http.Client{} |
20 | | - resp, err := client.Do(req) |
21 | | - if err != nil { |
22 | | - return nil, err |
23 | | - } |
| 9 | +func GetRepos(username string) (res map[string]interface{}, err error) { |
| 10 | + return Get(fmt.Sprintf("users/%s/repos", username)) |
| 11 | +} |
24 | 12 |
|
25 | | - defer func(Body io.ReadCloser) { |
26 | | - err := Body.Close() |
27 | | - if err != nil { |
28 | | - logrus.Infoln() |
29 | | - } |
30 | | - }(resp.Body) |
| 13 | +func GetRepo(username string, repo string) (res map[string]interface{}, err error) { |
| 14 | + return Get(fmt.Sprintf("repos/%s/%s", username, repo)) |
| 15 | +} |
31 | 16 |
|
32 | | - var data map[string]interface{} |
33 | | - err = json.NewDecoder(resp.Body).Decode(&data) |
34 | | - if err != nil { |
35 | | - return nil, err |
36 | | - } |
37 | | - return data, nil |
| 17 | +func GetLanguages(username string, repo string) (res map[string]interface{}, err error) { |
| 18 | + return Get(fmt.Sprintf("repos/%s/%s/languages", username, repo)) |
38 | 19 | } |
0 commit comments