instanciate templates at engine creation

this allow to use Delims() on HTMLTemplates before calling LoadHTMLTemplates()
so we can change delimmiters in templates.
This commit is contained in:
Christophe de Carvalho 2014-07-03 22:27:35 +02:00
parent 5eb0e10a78
commit 1c975b54dd

6
gin.go
View File

@ -74,7 +74,9 @@ func (a ErrorMsgs) String() string {
// Returns a new blank Engine instance without any middleware attached. // Returns a new blank Engine instance without any middleware attached.
// The most basic configuration // The most basic configuration
func New() *Engine { func New() *Engine {
engine := &Engine{} engine := &Engine{
HTMLTemplates: template.New(""),
}
engine.RouterGroup = &RouterGroup{nil, "/", nil, engine} engine.RouterGroup = &RouterGroup{nil, "/", nil, engine}
engine.router = httprouter.New() engine.router = httprouter.New()
engine.router.NotFound = engine.handle404 engine.router.NotFound = engine.handle404
@ -89,7 +91,7 @@ func Default() *Engine {
} }
func (engine *Engine) LoadHTMLTemplates(pattern string) { func (engine *Engine) LoadHTMLTemplates(pattern string) {
engine.HTMLTemplates = template.Must(template.ParseGlob(pattern)) engine.HTMLTemplates = template.Must(engine.HTMLTemplates.ParseGlob(pattern))
} }
// Adds handlers for NotFound. It return a 404 code by default. // Adds handlers for NotFound. It return a 404 code by default.