-
Notifications
You must be signed in to change notification settings - Fork 14
/
template.go
45 lines (34 loc) · 942 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
42
43
44
45
package template
import (
"bytes"
templatePackage "html/template"
"github.com/aymerick/raymond"
)
type ITemplateInterface interface {
RenderTemplate(html string, data interface{}) (string, error)
RenderMandrillTemplate(template string, data interface{}) (string, error)
}
type templateService struct {
}
func (t templateService) RenderTemplate(html string, data interface{}) (string, error) {
var templateBuffer bytes.Buffer
template, err := templatePackage.New("invoice").Parse(html)
if err != nil {
return "", err
}
err = template.Execute(&templateBuffer, data)
if err != nil {
return "", err
}
return templateBuffer.String(), nil
}
func (t templateService) RenderMandrillTemplate(template string, data interface{}) (string, error) {
html, err := raymond.Render(template, data)
if err != nil {
return "", err
}
return html, nil
}
func NewTemplateService() ITemplateInterface {
return &templateService{}
}