-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.go
54 lines (48 loc) · 1.47 KB
/
template.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
package main
import (
log "log"
"os"
"path"
"text/template"
)
var (
// all templates
goTmp = template.Must(template.ParseFiles(path.Join("cmd", "templates", "go.tmp")))
cppTmp = template.Must(template.ParseFiles(path.Join("cmd", "templates", "c++.tmp")))
goTestTmp = template.Must(template.ParseFiles(path.Join("cmd", "templates", "go_test.tmp")))
readmeTmp = template.Must(template.ParseFiles(path.Join("cmd", "templates", "readme.tmp")))
problemReadmeTmp = template.Must(template.ParseFiles(path.Join("cmd", "templates", "problem-readme.tmp")))
)
// SolutionData represents a unit solution block
type SolutionData struct {
Language string
FilePath string
}
// ProblemData represents a unit problem that is solved
type ProblemData struct {
Name string
Data string
Date string
Solutions []*SolutionData
}
// ReadmeData represents the statistic data to show in main README
type Data struct {
Days int
Solved int
Next string
Missed []string
Noteworthy []string
}
// renderTemplate: renders the template `tmp` using `data` into the file at location `into`
func renderTemplate(tmp *template.Template, into string, data interface{}) error {
file, err := os.Create(into)
if err != nil {
log.Printf("renderTemplate: file(%v) create error: %v\n", into, err)
return err
}
if err := tmp.Execute(file, data); err != nil {
log.Printf("renderTemplate: error for %v: %v\n", into, err)
return err
}
return nil
}