-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub_api.go
35 lines (26 loc) · 900 Bytes
/
github_api.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
package main
import (
"fmt"
"github.com/parnurzeal/gorequest"
)
const githubTrafficClonesURLTemplate = "https://api.github.com/repos/%s/%s/traffic/clones"
type trafficClonesResp struct {
Count int `json:"count"`
Uniques int `json:"uniques"`
Clones []clonesItem `json:"clones"`
}
type clonesItem struct {
Timestamp string `json:"timestamp"`
Count int `json:"count"`
Uniques int `json:"uniques"`
}
func getGithubTrafficClones(user, repoName, token string) (*trafficClonesResp, error) {
var trafficClonesResp trafficClonesResp
request := gorequest.New().Get(fmt.Sprintf(githubTrafficClonesURLTemplate, user, repoName))
request.Set("Authorization", "token "+token)
resp, _, errs := request.EndStruct(&trafficClonesResp)
if len(errs) != 0 {
return nil, fmt.Errorf("github api resp: %v, errors: %v", resp, errs)
}
return &trafficClonesResp, nil
}