generated from bmf-san/gobel-client-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
36 lines (31 loc) · 874 Bytes
/
error.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
package presenter
import (
"bytes"
"html/template"
"github.com/bmf-san/bmf-tech-client/app/model"
)
// ErrorData is a data for template.
type ErrorData struct {
Code int
Message string
}
// ExecuteError responses a error template.
func (p *Presenter) ExecuteError(buf *bytes.Buffer, code int) (*bytes.Buffer, error) {
e := &ErrorData{
Code: code,
Message: "すみません!エラーです!",
}
fm := template.FuncMap{
"year": p.year,
"isAd": p.IsAd,
}
m := &model.Meta{
Title: "bmf-tech.com - エラー",
NoIndex: true,
}
tpl := template.Must(template.New("base").Funcs(fm).ParseFS(p.templates, "templates/layout/base.tpl", "templates/partial/meta.tpl", "templates/error/index.tpl"))
if err := tpl.ExecuteTemplate(buf, "base", map[string]interface{}{"Meta": m, "ErrorData": e}); err != nil {
return nil, err
}
return buf, nil
}