-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontribution.go
82 lines (66 loc) · 1.92 KB
/
contribution.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"bytes"
"encoding/json"
"fmt"
"html/template"
"log"
)
type Contributor struct {
Login string `json:"login"`
Avatar_Url string `json:"avatar_url"`
Name string `json:"name"`
Url string `json:"url"`
Profile string `json:"profile"`
Contributions int `json:"contributions"`
ContributionType []string `json:"contribution_type"`
}
const (
GITHUB_CONTRIBUTOR_API_URL = "https://api.github.com/repos/Golang-Solutions/awesome-golang-algorithm/contributors"
GITHUB_CONTRIBUTOR_TMPL_PATH = "./tpl/.all-contributorsrc"
)
func getContributorBufer() []byte {
contributor_buffer := Request("GET", GITHUB_CONTRIBUTOR_API_URL, nil)
return contributor_buffer
}
func GetContributorString() string {
str := string(getContributorBufer())
return str
}
// get the josnmarshal json
func GetContributorJosnMarshal(prefix, indent string) string {
contributors := []Contributor{}
if err := json.Unmarshal(getContributorBufer(), &contributors); err != nil {
log.Fatalln(err.Error())
}
contributors_buffer, err := json.MarshalIndent(contributors, prefix, indent)
if err != nil {
log.Fatalln(err.Error())
}
return string(contributors_buffer)
}
func GetContributorInstance() []Contributor {
contributors := []Contributor{}
if err := json.Unmarshal(getContributorBufer(), &contributors); err != nil {
log.Fatalln(err.Error())
}
return contributors
}
func getContributorTemplate() string {
buffer := ReadFile(GITHUB_CONTRIBUTOR_TMPL_PATH)
return string(buffer)
}
func GenerateContributorTemplete() {
tpl_str := getContributorTemplate()
// fmt.Println(tpl_str)
contributors := GetContributorInstance()
fmt.Println(contributors)
// Tmpl
var tmpRes bytes.Buffer
tmpl, err := template.New("Contributors: ").Parse(tpl_str)
if err != nil {
log.Printf("%s", err)
}
err = tmpl.Execute(&tmpRes, contributors)
fmt.Println(string(tmpRes.Bytes()))
}