upgrade gin to v1.2 (#245)

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2017-07-04 04:03:06 -05:00
committed by GitHub
parent 17229a17f8
commit 02f0390d4d
19 changed files with 765 additions and 65 deletions

View File

@@ -10,17 +10,25 @@ import (
)
type (
Delims struct {
Left string
Right string
}
HTMLRender interface {
Instance(string, interface{}) Render
}
HTMLProduction struct {
Template *template.Template
Delims Delims
}
HTMLDebug struct {
Files []string
Glob string
Files []string
Glob string
Delims Delims
FuncMap template.FuncMap
}
HTML struct {
@@ -48,11 +56,14 @@ func (r HTMLDebug) Instance(name string, data interface{}) Render {
}
}
func (r HTMLDebug) loadTemplate() *template.Template {
if r.FuncMap == nil {
r.FuncMap = template.FuncMap{}
}
if len(r.Files) > 0 {
return template.Must(template.ParseFiles(r.Files...))
return template.Must(template.New("").Delims(r.Delims.Left, r.Delims.Right).Funcs(r.FuncMap).ParseFiles(r.Files...))
}
if len(r.Glob) > 0 {
return template.Must(template.ParseGlob(r.Glob))
return template.Must(template.New("").Delims(r.Delims.Left, r.Delims.Right).Funcs(r.FuncMap).ParseGlob(r.Glob))
}
panic("the HTML debug render was created without files or glob pattern")
}