Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ERRO] 2018/01/13 12:33 html/template: cannot Parse after Execute #872

Closed
forchid opened this issue Jan 13, 2018 · 4 comments
Closed

[ERRO] 2018/01/13 12:33 html/template: cannot Parse after Execute #872

forchid opened this issue Jan 13, 2018 · 4 comments

Comments

@forchid
Copy link

forchid commented Jan 13, 2018

// The case when concurrent access!
//
// - go version go1.9.1 windows/amd64
// - Iris-10.0.0
//
// template config
tpl := iris.HTML(configuration.TplBae, Tpl_suffix)
// reload templates on each request (development mode!)
tpl.Reload(true)

@kataras
Copy link
Owner

kataras commented Jan 13, 2018

Of course it can't parse after execute, this is html/template thing and it's normal behavior, but it parses the file on each request because you have .Reload(true) if you disable it(as you MUST do on production) then you're are fine, the templates are parsed once.

@forchid
Copy link
Author

forchid commented Jan 14, 2018

Then the method Reload() should be deprecated, or we can sync road and execute if reload is true in dev mode.

@kataras
Copy link
Owner

kataras commented Jan 14, 2018

Why deprecated man? It's not created to be used like that, it's inside the html/template we can't add lockers there but I added locks to Load so it should be fixed now, although I don't think that's important, Reload is never used on a real app. Try it and tell me the results, thank you!

@forchid
Copy link
Author

forchid commented Jan 16, 2018

No problem in product environment, but it is unavailable in dev mode! In dev mode(set Reload(true)), it's not convenient to modify template file that can lead to parse error! So ... the method Reload() should be deprecated, or we can sync road and execute if reload is true in dev mode.

I had sync the block following, it's work in dev mode.
//
// ExecuteWriter executes a template and writes its result to the w writer.
func (s *HTMLEngine) ExecuteWriter(w io.Writer, name string, layout string, bindingData interface{}) error {
// reload the templates if reload configuration field is true
if s.reload {
// ensure that work in dev mode only!
s.muReload.Lock()
defer s.muReload.Unlock()

if err := s.Load(); err != nil {
return err
}
}

layout = getLayout(layout, s.layout)

if layout != "" {
	s.layoutFuncsFor(name, bindingData)
	name = layout
} else {
	s.runtimeFuncsFor(name, bindingData)
}

return s.Templates.ExecuteTemplate(w, name, bindingData)

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants