-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Refactor fasthttp iter calls to range loops #3559
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
Conversation
WalkthroughThis update refactors multiple files to replace callback-style iteration over headers, cookies, and form/query parameters with idiomatic Go Changes
Sequence Diagram(s)sequenceDiagram
participant Request
participant Binder
participant DataMap
Request->>Binder: Call Bind(req, out)
Binder->>DataMap: for key, value := range Collection
DataMap->>Binder: formatBindData(key, value)
alt Error occurs
Binder-->>Request: return error
else All ok
Binder-->>Request: return nil
end
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (15)
🧰 Additional context used🧠 Learnings (12)📓 Common learningsbinder/resp_header.go (2)middleware/adaptor/adaptor.go (3)binder/cookie.go (2)middleware/encryptcookie/encryptcookie.go (9)client/hooks.go (3)middleware/cors/cors_test.go (3)client/client_test.go (7)middleware/cache/cache.go (2)client/cookiejar.go (2)ctx.go (5)client/request_test.go (4)🧬 Code Graph Analysis (5)client/hooks.go (1)
middleware/cors/cors_test.go (3)
client/client_test.go (1)
middleware/cache/cache.go (2)
client/request_test.go (1)
⏰ Context from checks skipped due to timeout of 90000ms (8)
🔇 Additional comments (25)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @ReneWerner87, 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 refactors several parts of the codebase by replacing fasthttp's callback-based iteration patterns with more idiomatic and readable Go for...range loops. The primary goal is to enhance code clarity and maintainability while ensuring that the original functional behavior, including early exit conditions on errors, remains unchanged.
Highlights
- Code Refactoring: Replaced
fasthttp's callback-style iteration (e.g.,req.Header.Cookies()(func(...) bool { ... })) with standard Gofor...rangeloops for improved readability and idiomatic Go. - Functional Equivalence: Ensured that the original early-exit behavior, where iterations would stop upon encountering an error, is preserved by using
breakstatements within the newfor...rangeconstructs. - Scope of Changes: Applied this refactoring consistently across various components, including
binder(for cookies, forms, headers, queries, response headers),client(for headers, cookies, hooks, requests),ctx(for cookies, headers, queries, scheme), andmiddleware(adaptor, cache, CORS, encryptcookie).
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and 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 to provide feedback.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors various iterations over fasthttp headers, cookies, query args, and form data by replacing callback-based iterators with simple Go for-range loops, while preserving early-exit behavior on errors.
- Replaced
.All()(func)and.Cookies()(func)callback patterns withfor key, value := range ...loops. - Introduced
breakorcontinuestatements to maintain the original early-exit semantics. - Applied changes across middleware, client, and binder packages, including tests.
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| middleware/encryptcookie/encryptcookie.go | Iteration switched to for-range for request/response cookies |
| middleware/cors/cors_test.go | Updated test header iteration to for-range |
| middleware/cache/cache.go | Refactored header iteration to for-range |
| middleware/adaptor/adaptor.go | Converted header iteration to for-range |
| ctx.go | Updated various header/query/cookie iterations to for-range |
| client/request_test.go | Converted request header iteration in tests to for-range |
| client/request.go | Refactored Header.PeekMultiple and parameter iteration to for-range |
| client/hooks.go | Switched param/header/form data iterations to for-range |
| client/cookiejar.go | Updated cookie parsing loop to for-range |
| client/client_test.go | Converted request header iteration in tests to for-range |
| binder/resp_header.go | Replaced header binding iteration with for-range |
| binder/query.go | Refactored query binding iteration to for-range |
| binder/header.go | Updated header binding iteration to for-range |
| binder/form.go | Converted form binding iteration to for-range |
| binder/cookie.go | Refactored cookie binding iteration to for-range |
Comments suppressed due to low confidence (1)
middleware/cache/cache.go:259
- [nitpick] Use a consistent variable name when converting keys to strings (e.g.,
keyString) to match patterns in other files.
keyS := string(key)
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3559 +/- ##
==========================================
- Coverage 91.05% 90.97% -0.08%
==========================================
Files 110 110
Lines 11084 11064 -20
==========================================
- Hits 10092 10065 -27
- Misses 742 745 +3
- Partials 250 254 +4
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request refactors fasthttp iterator callbacks to use Go's native for...range loops. The changes correctly preserve the original logic, including early exits on errors.
ksw2000
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Summary
forloopsTesting
make testhttps://chatgpt.com/codex/tasks/task_e_6863c67370e88326b2ce7ad1f4a61afb