🔥 feat: Add support for ReloadViews()#3876
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdded a new public method Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant App
participant Mutex
participant Engine
Client->>App: ReloadViews()
App->>Mutex: Lock()
Mutex-->>App: Locked
alt Views configured (non-nil)
App->>Engine: Load()
alt Load succeeds
Engine-->>App: nil
App-->>Client: nil
else Load fails
Engine-->>App: error
App-->>Client: wrapped error ("fiber: failed to reload views: ...")
end
else No view engine configured (nil or nil-pointer)
App-->>Client: ErrNoViewEngineConfigured
end
App->>Mutex: Unlock()
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used🧬 Code graph analysis (1)app_test.go (3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
🔇 Additional comments (5)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @gaby, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the application's view management by introducing a Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3876 +/- ##
=======================================
Coverage 91.64% 91.65%
=======================================
Files 115 115
Lines 9848 9858 +10
=======================================
+ Hits 9025 9035 +10
Misses 523 523
Partials 300 300
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a reusable sentinel error ErrNoViewEngineConfigured and a new ReloadViews() method that allows reloading the view engine on demand without restarting the server.
- Adds a shared sentinel error for view engine configuration issues
- Implements thread-safe view engine reloading functionality
- Provides comprehensive test coverage for all scenarios
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| error.go | Adds ErrNoViewEngineConfigured sentinel error following existing error definition patterns |
| app.go | Implements thread-safe ReloadViews() method with proper mutex locking and error handling |
| app_test.go | Adds three comprehensive test cases covering success, error, and no-engine scenarios |
| docs/api/app.md | Documents the new ReloadViews() method with clear description and practical example |
There was a problem hiding this comment.
Code Review
This pull request introduces a new ReloadViews method to allow on-demand reloading of the view engine, which is a great addition for development workflows. It also adds a corresponding sentinel error ErrNoViewEngineConfigured, which is good practice. The implementation is clean, and it's well-documented and tested. I've found one potential issue regarding a nil pointer panic that could occur with a specific configuration, and I've provided a suggestion to make the new function more robust. Overall, this is a solid contribution.
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.
| Benchmark suite | Current: 55c984c | Previous: f15a193 | Ratio |
|---|---|---|---|
Benchmark_NewError |
80.24 ns/op 24 B/op 1 allocs/op |
38.96 ns/op 24 B/op 1 allocs/op |
2.06 |
Benchmark_NewError - ns/op |
80.24 ns/op |
38.96 ns/op |
2.06 |
This comment was automatically generated by workflow using github-action-benchmark.
ReneWerner87
left a comment
There was a problem hiding this comment.
Pls add something in the What´s new.md
|
I have just tested this PR by using fsnotify to detect a change in the views and then triggering I'm using the following engine: engine = html.New(cwd, ".html")The reload happens like this (simplified): srv.watcher, err = srv.getWatcher(cwd+"/views", func(f string) {
err := srv.app.ReloadViews()
if err != nil {
Error("error", err)
}
})
func (srv *Web) getWatcher(path string, callback func(f string)) (*fsnotify.Watcher, error) {
watcher, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
}
go func() {
for {
select {
case ev, ok := <-watcher.Events:
if !ok {
return
}
if ev.Has(fsnotify.Write) {
callback(ev.Name)
}
case err, ok := <-watcher.Errors:
if !ok {
return
}
Error("error", err)
}
}
}()
if err = watcher.Add(path); err != nil {
watcher.Close()
return nil, err
}
return watcher, nil
}Either it is an issue that the |
Summary
Fixes #3875