/
template.go
35 lines (29 loc) · 734 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
package formats
import (
"io"
"text/template"
)
type TemplateFormat struct {
rows []map[string]interface{}
template *template.Template
writer io.Writer
}
func NewTemplateFormat(w io.Writer, rawTemplate string) *TemplateFormat {
t := template.Must(template.New("climbtemplate").Parse(rawTemplate))
return &TemplateFormat{
rows: make([]map[string]interface{}, 0),
template: t,
writer: w,
}
}
func (e *TemplateFormat) Flush() error {
err := e.template.Execute(e.writer, e.rows)
return err
}
func (e *TemplateFormat) WriteHeader(columns []string) error {
return nil
}
func (e *TemplateFormat) WriteRow(values map[string]interface{}) error {
e.rows = append(e.rows, convertToJSON(values))
return nil
}