-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
client: add support for iterator methods #3228
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe pull request introduces significant enhancements to the handling of HTTP requests and responses in the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 (
|
fe2a14f
to
7578ae3
Compare
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.
Actionable comments posted: 10
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (5)
client/hooks.go
(2 hunks)client/request.go
(9 hunks)client/request_test.go
(7 hunks)client/response.go
(2 hunks)client/response_test.go
(2 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
client/hooks.go
[warning] 276-276: unhandled-error: Unhandled error in call to function io.CopyBuffer
(revive)
276-276: Error return value of io.CopyBuffer
is not checked
(errcheck)
client/response_test.go
[warning] 229-229: unhandled-error: Unhandled error in call to function fmt.Print
(revive)
229-229: use of fmt.Print
forbidden by pattern ^fmt\.Print(f|ln)?$
(forbidigo)
229-229: Error return value of fmt.Print
is not checked
(errcheck)
229-229: unnecessary conversion
(unconvert)
230-230: unnecessary conversion
(unconvert)
[warning] 273-273: empty-block: this block is empty, you can remove it
(revive)
client/request.go
735-735: append to slice keys
with non-zero initialized length
(makezero)
875-875: append to slice keys
with non-zero initialized length
(makezero)
client/request_test.go
[warning] 190-190: empty-block: this block is empty, you can remove it
(revive)
[warning] 349-349: empty-block: this block is empty, you can remove it
(revive)
[warning] 464-464: empty-block: this block is empty, you can remove it
(revive)
[warning] 574-574: empty-block: this block is empty, you can remove it
(revive)
🪛 GitHub Check: lint
client/hooks.go
[failure] 276-276:
unhandled-error: Unhandled error in call to function io.CopyBuffer (revive)
[failure] 276-276:
Error return value of io.CopyBuffer
is not checked (errcheck)
client/request.go
[failure] 734-734:
unused-parameter: parameter 'value' seems to be unused, consider removing or renaming it as _ (revive)
[failure] 735-735:
append to slice keys
with non-zero initialized length (makezero)
[failure] 874-874:
unused-parameter: parameter 'value' seems to be unused, consider removing or renaming it as _ (revive)
[failure] 875-875:
append to slice keys
with non-zero initialized length (makezero)
🔇 Additional comments (3)
client/request_test.go (1)
8-8
: Verify compatibility of the maps
package with the project's Go version
The maps
package was introduced in Go 1.21. Please ensure that the project's minimum Go version is at least 1.21 or update it accordingly to avoid build issues.
client/response.go (2)
59-80
: Ensure safe usage of utils.UnsafeString
in Headers
method
The Headers
method uses utils.UnsafeString
to convert byte slices to strings. While this is efficient, ensure that the byte slices are not modified elsewhere to prevent unexpected behavior due to string aliasing.
83-85
: Documentation for Cookies
method is clear and informative
The updated comments provide essential information about the validity and usage of the returned cookies, promoting correct usage.
for i := 0; i < b.N; i++ { | ||
for range req.Cookies() { | ||
} |
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.
🛠️ Refactor suggestion
Empty loop in Benchmark_Request_Cookies
may lead to misleading results
The inner loop in the Benchmark_Request_Cookies
function is empty. This may cause inaccurate benchmarking due to compiler optimizations. Add operations inside the loop to measure cookie iteration performance.
Apply this diff:
for i := 0; i < b.N; i++ {
- for range req.Cookies() {
- }
+ for key, value := range req.Cookies() {
+ _ = key
+ _ = value
+ }
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
for i := 0; i < b.N; i++ { | |
for range req.Cookies() { | |
} | |
for i := 0; i < b.N; i++ { | |
for key, value := range req.Cookies() { | |
_ = key | |
_ = value | |
} |
🧰 Tools
🪛 golangci-lint (1.62.2)
[warning] 464-464: empty-block: this block is empty, you can remove it
(revive)
for range req.PathParams() { | ||
} |
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.
🛠️ Refactor suggestion
Empty loop in Benchmark_Request_PathParams
may lead to misleading results
The inner loop in the Benchmark_Request_PathParams
function is empty. This could lead to the compiler optimizing it away. Include meaningful operations to benchmark path parameter iteration effectively.
Apply this diff:
for i := 0; i < b.N; i++ {
- for range req.PathParams() {
- }
+ for key, value := range req.PathParams() {
+ _ = key
+ _ = value
+ }
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
for range req.PathParams() { | |
} | |
for key, value := range req.PathParams() { | |
_ = key | |
_ = value | |
} |
🧰 Tools
🪛 golangci-lint (1.62.2)
[warning] 574-574: empty-block: this block is empty, you can remove it
(revive)
for i := 0; i < b.N; i++ { | ||
for range req.Params() { | ||
} |
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.
🛠️ Refactor suggestion
Empty loop in Benchmark_Request_Params
may lead to misleading results
The inner loop in the Benchmark_Request_Params
function is empty. This could result in the compiler optimizing out the loop. Include meaningful operations inside the loop to accurately benchmark parameter iteration.
Apply this diff:
for i := 0; i < b.N; i++ {
- for range req.Params() {
- }
+ for key, values := range req.Params() {
+ _ = key
+ _ = values
+ }
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
for i := 0; i < b.N; i++ { | |
for range req.Params() { | |
} | |
for i := 0; i < b.N; i++ { | |
for key, values := range req.Params() { | |
_ = key | |
_ = values | |
} |
🧰 Tools
🪛 golangci-lint (1.62.2)
[warning] 349-349: empty-block: this block is empty, you can remove it
(revive)
for range req.Headers() { | ||
} | ||
} |
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.
🛠️ Refactor suggestion
Empty loop in Benchmark_Request_Headers
may lead to misleading results
The inner loop in the Benchmark_Request_Headers
function is empty. This might cause the compiler to optimize away the loop, leading to inaccurate benchmarking. Consider performing an operation inside the loop to measure the performance effectively.
Apply this diff to include an operation inside the loop:
for i := 0; i < b.N; i++ {
- for range req.Headers() {
- }
+ for key, values := range req.Headers() {
+ _ = key
+ _ = values
+ }
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
for range req.Headers() { | |
} | |
} | |
for key, values := range req.Headers() { | |
_ = key | |
_ = values | |
} | |
} |
🧰 Tools
🪛 golangci-lint (1.62.2)
[warning] 190-190: empty-block: this block is empty, you can remove it
(revive)
for range req.FormDatas() { | ||
} |
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.
🛠️ Refactor suggestion
Empty loop in Benchmark_Request_FormDatas
may lead to misleading results
The inner loop in the Benchmark_Request_FormDatas
function is empty. This may result in the compiler optimizing away the loop, leading to inaccurate benchmarks. Add operations inside the loop to measure form data iteration performance.
Apply this diff:
for i := 0; i < b.N; i++ {
- for range req.FormDatas() {
- }
+ for key, values := range req.FormDatas() {
+ _ = key
+ _ = values
+ }
}
Committable suggestion skipped: line range outside the PR's diff.
for range resp.Headers() { | ||
} |
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.
🛠️ Refactor suggestion
Empty loop in Benchmark_Headers
may lead to misleading results
The inner loop in the Benchmark_Headers
function is empty. This can cause the compiler to optimize it away, making the benchmark ineffective. Include operations inside the loop to measure header iteration performance accurately.
Apply this diff:
for i := 0; i < b.N; i++ {
- for range resp.Headers() {
- }
+ for key, values := range resp.Headers() {
+ _ = key
+ _ = values
+ }
}
Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 golangci-lint (1.62.2)
[warning] 273-273: empty-block: this block is empty, you can remove it
(revive)
for k, v := range resp.Headers() { | ||
headers[k] = make([]string, 0) | ||
for _, value := range v { | ||
fmt.Print(string(value)) |
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.
🛠️ Refactor suggestion
Remove fmt.Print
statement from test to avoid cluttering output
Using fmt.Print
in tests can clutter the test output and is generally discouraged. Instead, use assertions to validate the values.
Apply this diff to remove the print statement:
for _, value := range v {
- fmt.Print(string(value))
headers[k] = append(headers[k], string(value))
}
Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 golangci-lint (1.62.2)
[warning] 229-229: unhandled-error: Unhandled error in call to function fmt.Print
(revive)
229-229: use of fmt.Print
forbidden by pattern ^fmt\.Print(f|ln)?$
(forbidigo)
229-229: Error return value of fmt.Print
is not checked
(errcheck)
229-229: unnecessary conversion
(unconvert)
keys := make([]string, f.Len()) | ||
f.VisitAll(func(key, value []byte) { | ||
keys = append(keys, utils.UnsafeString(key)) | ||
}) | ||
|
||
return slices.Compact(keys) | ||
} |
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.
🛠️ Refactor suggestion
Optimize slice initialization and address unused parameter in FormData.Keys
Similar to the QueryParam.Keys
method, initialize the keys
slice with zero length and capacity of f.Len()
. Also, rename the unused value
parameter to _
.
Apply this diff:
func (f *FormData) Keys() []string {
- keys := make([]string, f.Len())
+ keys := make([]string, 0, f.Len())
- f.VisitAll(func(key, value []byte) {
+ f.VisitAll(func(key, _ []byte) {
keys = append(keys, utils.UnsafeString(key))
})
return slices.Compact(keys)
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
keys := make([]string, f.Len()) | |
f.VisitAll(func(key, value []byte) { | |
keys = append(keys, utils.UnsafeString(key)) | |
}) | |
return slices.Compact(keys) | |
} | |
keys := make([]string, 0, f.Len()) | |
f.VisitAll(func(key, _ []byte) { | |
keys = append(keys, utils.UnsafeString(key)) | |
}) | |
return slices.Compact(keys) | |
} |
🧰 Tools
🪛 golangci-lint (1.62.2)
875-875: append to slice keys
with non-zero initialized length
(makezero)
🪛 GitHub Check: lint
[failure] 874-874:
unused-parameter: parameter 'value' seems to be unused, consider removing or renaming it as _ (revive)
[failure] 875-875:
append to slice keys
with non-zero initialized length (makezero)
// Keys method returns all keys in the query params. | ||
func (f *QueryParam) Keys() []string { | ||
keys := make([]string, f.Len()) | ||
f.VisitAll(func(key, value []byte) { | ||
keys = append(keys, utils.UnsafeString(key)) | ||
}) | ||
|
||
return slices.Compact(keys) | ||
} |
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.
🛠️ Refactor suggestion
Optimize slice initialization and address unused parameter in QueryParam.Keys
In the Keys
method, the slice keys
is initialized with a non-zero length and then appended to, leading to unintended zero values at the beginning. Additionally, the value
parameter in VisitAll
is unused.
Apply this diff:
func (f *QueryParam) Keys() []string {
- keys := make([]string, f.Len())
+ keys := make([]string, 0, f.Len())
- f.VisitAll(func(key, value []byte) {
+ f.VisitAll(func(key, _ []byte) {
keys = append(keys, utils.UnsafeString(key))
})
return slices.Compact(keys)
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
// Keys method returns all keys in the query params. | |
func (f *QueryParam) Keys() []string { | |
keys := make([]string, f.Len()) | |
f.VisitAll(func(key, value []byte) { | |
keys = append(keys, utils.UnsafeString(key)) | |
}) | |
return slices.Compact(keys) | |
} | |
// Keys method returns all keys in the query params. | |
func (f *QueryParam) Keys() []string { | |
keys := make([]string, 0, f.Len()) | |
f.VisitAll(func(key, _ []byte) { | |
keys = append(keys, utils.UnsafeString(key)) | |
}) | |
return slices.Compact(keys) | |
} |
🧰 Tools
🪛 golangci-lint (1.62.2)
735-735: append to slice keys
with non-zero initialized length
(makezero)
🪛 GitHub Check: lint
[failure] 734-734:
unused-parameter: parameter 'value' seems to be unused, consider removing or renaming it as _ (revive)
[failure] 735-735:
append to slice keys
with non-zero initialized length (makezero)
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.
⚠️ 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: 26a3439 | Previous: 9a2ceb7 | Ratio |
---|---|---|---|
BenchmarkDecoderedirectionMsgs |
13.81 ns/op 72.44 MB/s 0 B/op 0 allocs/op |
8.381 ns/op 119.32 MB/s 0 B/op 0 allocs/op |
1.65 |
BenchmarkDecoderedirectionMsgs - ns/op |
13.81 ns/op |
8.381 ns/op |
1.65 |
This comment was automatically generated by workflow using github-action-benchmark.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Description
parserRequestFile
logic using io.CopyTodo:
Fixes #3184
Changes introduced
Type of change
Checklist
/docs/
directory for Fiber's documentation.Commit formatting
Please use emojis in commit messages for an easy way to identify the purpose or intention of a commit. Check out the emoji cheatsheet here: CONTRIBUTING.md