♻️ refactor: use slices.Contains to simplify code#3486
♻️ refactor: use slices.Contains to simplify code#3486ReneWerner87 merged 1 commit intogofiber:mainfrom
Conversation
Signed-off-by: tongjicoder <tongjicoder@icloud.com>
|
Thanks for opening this pull request! 🎉 Please check out our contributing guidelines. If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
WalkthroughThe changes across several files replace manual iteration over slices for membership checks with the standard library function Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (4)
🔇 Additional comments (9)
✨ 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 (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3486 +/- ##
==========================================
+ Coverage 83.76% 83.82% +0.05%
==========================================
Files 120 120
Lines 12254 12246 -8
==========================================
Hits 10265 10265
+ Misses 1564 1558 -6
+ Partials 425 423 -2
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:
|
|
i like the idea but its slower at the moment var (
trustedOrigins = []string{
"https://example.com",
"https://static.example.com",
"https://api.example.com",
"https://cdn.example.com",
}
benchResult bool
origin = "https://api.example.com"
)
func BenchmarkTrustedOrigin(b *testing.B) {
b.Run("for-loop", func(b *testing.B) {
var found bool
for b.Loop() {
found = false
for _, trusted := range trustedOrigins {
if origin == trusted {
found = true
break
}
}
}
benchResult = found
})
b.Run("slices-contains", func(b *testing.B) {
var found bool
for b.Loop() {
found = slices.Contains(trustedOrigins, origin)
}
benchResult = found
})
}go test . -v -bench=BenchmarkTrustedOrigin -benchmem -run=^$ -count=10 -benchtime=1s |
|
1ns slower is acceptable the function will certainly be optimized later |
|
Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
Description
There is a new function added in the go1.21 standard library, which can make the code more concise and easy to read.
Fixes # (issue)
Changes introduced
List the new features or adjustments introduced in this pull request. Provide details on benchmarks, documentation updates, changelog entries, and if applicable, the migration guide.
Type of change
Please delete options that are not relevant.
Checklist
Before you submit your pull request, please make sure you meet these requirements:
/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