2018-05-27 22:40:42 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-06-09 16:27:47 +08:00
|
|
|
"os"
|
2018-05-27 22:40:42 +08:00
|
|
|
"fmt"
|
|
|
|
"html/template"
|
|
|
|
)
|
|
|
|
|
|
|
|
var headerTemplate *template.Template
|
|
|
|
|
|
|
|
type headerPlugs struct {
|
|
|
|
FromAddress string
|
|
|
|
ToName string
|
|
|
|
ToAddress string
|
|
|
|
Subject string
|
|
|
|
}
|
|
|
|
|
|
|
|
var templates map[string]*template.Template
|
|
|
|
|
|
|
|
func loadTemplates() error {
|
|
|
|
var err error
|
|
|
|
headerTemplate, err = template.New("header").Parse(`MIME-Version: 1.0
|
|
|
|
Content-Type: text/html; charset=UTF-8
|
|
|
|
From: {{.FromAddress}}
|
|
|
|
To: {{.ToName}} <{{.ToAddress}}>
|
|
|
|
Subject: {{.Subject}}
|
|
|
|
|
|
|
|
`)
|
|
|
|
if err != nil {
|
|
|
|
logger.Fatalf("cannot parse header template: %v", err)
|
|
|
|
return errorMalformedTemplate
|
|
|
|
}
|
|
|
|
|
|
|
|
names := []string{"confirm-hex"}
|
|
|
|
|
|
|
|
templates = make(map[string]*template.Template)
|
|
|
|
|
|
|
|
logger.Infof("loading templates: %v", names)
|
|
|
|
for _, name := range names {
|
|
|
|
var err error
|
|
|
|
templates[name] = template.New(name)
|
2018-06-09 16:27:47 +08:00
|
|
|
templates[name], err = template.ParseFiles(fmt.Sprintf("%s/templates/%s.html", os.Getenv("COMMENTO_STATIC"), name))
|
2018-05-27 22:40:42 +08:00
|
|
|
if err != nil {
|
2018-06-09 16:27:47 +08:00
|
|
|
logger.Fatalf("cannot parse %s/templates/%s.html: %v", os.Getenv("STATIC"), name, err)
|
2018-05-27 22:40:42 +08:00
|
|
|
return errorMalformedTemplate
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|