Proposal: Add reload mechanism to html render
Describe the solution you'd like
Add or replace the way of rendering HTML in order to let the server reload HTML templates without restarting.
Describe alternatives you've considered
A timer or a file system watcher may help to decide whether to reload or not.
Additional context
Be aware of performance overhead. DO NOT reload it every time when render api is called.
I would like to help with this issue
Some of my thoughts on this issue
- By analyzing the source code of hertz, I found that the method of loading HTML is located in
pkg/route/engine.go, and there are two main functions inengine.gowhich are responsible for executing loading HTML, namelyLoadHTMLGlobandLoadHTMLFiles - As mentioned in the description of the issue above, consider using a timer or watcher to listen to the file system, I think we can use a channel to listen for events and perform a reload once the files in the directory change (read or write)
Yes, LoadHTMLGlob and LoadHTMLFiles will set the HTMLRender immediately, so here a new auto-reloading Render may help do the reload job(check the files during .Instance()).
stage 1 of the impl: users can choose the auto-reloading Render for their project. stage2 : switching automatically between normal Render and auto-reloading Render according to some conditions(maybe config/env/etc.)
possible to get ideas from here? it's the fastest templating engine but doesnt do live reload https://github.com/Joker/jade
Hi~ I am wondering how it's going? Do you encounter any difficulties? You may join our Feishu Chat Group to discuss more details about this task.
Hi~ I am wondering how it's going? Do you encounter any difficulties? You may join our Feishu Chat Group to discuss more details about this task.
Sorry I just saw your message, I have been in hospital for a month, I'm sorry to reply to you too late
what during .Instance() mean ? auto-reloading Render may add some time conditions such as cron ? and set a default cron if is auto-reloading Render
i see fiber support this ,every time do the Render() will the tpl be reloaded if engine.reload is ture
https://github.com/gofiber/fiber/blob/c450072f4a490355dffc31f5cc36036a2383b1c7/internal/template/html/html.go#L187
so may hertz do as fiber ?