-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.go
42 lines (37 loc) · 827 Bytes
/
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
// +build ignore
package main
import (
"io/ioutil"
"log"
"os"
"text/template"
"time"
)
var mainTmpl = `
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// {{ .Time }}
package main
var feedTmpl = ` + "`{{.Body}}`" + `
`
func main() {
tmpl, err := template.New("template").Parse(mainTmpl)
if err != nil {
log.Fatalf("could not parse template: %v", err)
}
body, err := ioutil.ReadFile("template.html")
if err != nil {
log.Fatalf("could not open template: %v", err)
}
w, err := os.Create("template.go")
if err != nil {
log.Fatalf("could not create generated template file: %v", err)
}
data := struct {
Time time.Time
Body string
}{time.Now(), string(body)}
if err := tmpl.Execute(w, data); err != nil {
log.Fatalf("could not execute template: %v", err)
}
}