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

Proposal: Add reload mechanism to html render #95

Closed
welkeyever opened this issue Jun 23, 2022 · 8 comments · Fixed by #207
Closed

Proposal: Add reload mechanism to html render #95

welkeyever opened this issue Jun 23, 2022 · 8 comments · Fixed by #207
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@welkeyever
Copy link
Member

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.

@welkeyever welkeyever added good first issue Good for newcomers enhancement New feature or request labels Jun 23, 2022
@stephenzhang0713
Copy link

I would like to help with this issue

@stephenzhang0713
Copy link

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 in engine.go which are responsible for executing loading HTML, namely LoadHTMLGlob and LoadHTMLFiles
  • 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)

@welkeyever
Copy link
Member Author

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.)

@hiqsociety
Copy link

possible to get ideas from here? it's the fastest templating engine but doesnt do live reload
https://github.com/Joker/jade

@Duslia
Copy link
Member

Duslia commented Jul 7, 2022

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.

@stephenzhang0713
Copy link

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

@stephenzhang0713 stephenzhang0713 removed their assignment Aug 1, 2022
@byene0923
Copy link
Member

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

@byene0923
Copy link
Member

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
5 participants