-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.go
41 lines (36 loc) · 945 Bytes
/
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
package main
import (
"fmt"
"os"
"sort"
"text/template"
"time"
)
func writeFile(outputFilename string, results *ServerCrontabs) {
file, err := os.OpenFile(outputFilename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
halt("opening file failed: " + err.Error())
}
defer file.Close()
templateFuncs := template.FuncMap{
"creationTime": templateCreationTime,
"version": templateVersion,
}
data, err := Asset("templates/overview.tpl.html")
if err != nil {
halt("missing template")
}
template := template.Must(template.New("overview.tpl").Funcs(templateFuncs).Parse(string(data[:])))
sort.Sort(results)
err = template.Execute(file, results)
if err != nil {
halt("writing file failed: " + err.Error())
}
fmt.Println("... wrote to file", outputFilename)
}
func templateCreationTime() string {
return time.Now().Format("2006-01-02 15:04 MST")
}
func templateVersion() string {
return "v" + VERSION
}