-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate.go
74 lines (58 loc) · 1.42 KB
/
generate.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
package mystars
import (
"bufio"
"fmt"
"os"
"time"
)
type Generater struct {
w *bufio.Writer
}
func NewGenerater(file *os.File) *Generater {
return &Generater{
w: bufio.NewWriter(file),
}
}
func (g *Generater) Title() (int, error) {
date := time.Now().Format(time.RFC1123Z)
return g.w.WriteString("# My Stars\nUpdated at: " + date + "\n\n")
}
func (g *Generater) Desc() (int, error) {
c1 := "`"
c3 := "```"
template := `Usage:
1. Get a access token from [github](https://github.com/settings/tokens)
2. Execute:
%sbash
go run github.com/xiaoler/mystars/cmd/main.go -o README.md -t {your token}
%s
You can also set the env variable %sGITHUB_TOKEN%s .
If use the Github Action, please set up %ssecrets.UPDATE_TOKEN%s.
`
s := fmt.Sprintf(template, c3, c3, c1, c1, c1, c1)
return g.w.WriteString(s)
}
func (g *Generater) Category(lang string) (int, error) {
return g.w.WriteString("\n### " + lang + "\n")
}
func (g *Generater) Link(name, url string) (int, error) {
s := fmt.Sprintf("- [%s](%s)\n", name, url)
return g.w.WriteString(s)
}
func (g *Generater) Separator() (int, error) {
return g.w.WriteString("\n---\n")
}
func (g *Generater) Repo(abst *Abstract) (int, error) {
template := "- [%s](%s) - %s (`stars: %d`, `license: %s`)\n"
s := fmt.Sprintf(template,
abst.Name,
abst.Url,
abst.Desc,
abst.StarCount,
abst.License,
)
return g.w.WriteString(s)
}
func (g *Generater) Flush() {
g.w.Flush()
}