docs: document utils package migration#3704
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. Warning Rate limit exceeded@ReneWerner87 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 22 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughDocumentation update to docs/whats_new.md adds a Utils section, a utils-migration guide, and enumerates public API changes for Fiber v3 (router methods, Route/Add, Test config, hooks, constants, configs, middleware shifts). It documents externalizing utils to github.com/gofiber/utils and introduces new helpers and generics. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Dev as Developer
participant R as Router
participant App as Fiber App
Note over Dev,R: Register routes with new signatures (v3)
Dev->>R: Get(path, handler, middleware...)
R->>App: Add([GET], path, handler, middleware...)
Dev->>R: Route(path)
R-->>Dev: Register (for chaining)
Note over Dev,App: Test API uses TestConfig (v3)
Dev->>App: Test(req, TestConfig{...})
App-->>Dev: *http.Response, error
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches🧪 Generate unit tests
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. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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 updates the documentation for Fiber v3 to reflect the significant change in how utility functions are handled. It clarifies that the internal utils package has been replaced by an external Go module, github.com/gofiber/utils. The changes include adding new sections to the 'What's New' and migration guides, providing clear instructions, function mapping tables, and code examples to assist developers in adapting their code to this new structure. The aim is to ensure a smooth transition for users migrating to Fiber v3 by providing comprehensive and accessible documentation for this core change.
Highlights
- External
utilsmodule adoption: The documentation now clearly states that Fiber v3 has removed its built-inutilsdirectory, opting instead to import utility helpers from the separategithub.com/gofiber/utilsmodule. - Comprehensive migration guide for
utils: A new, dedicated section in the migration guide provides detailed steps for migrating from the old in-repoutilsto the new external module, including import changes, a comprehensive mapping table of v2 functions to v3 replacements, and practical code examples. - Introduction of new utility helpers: The documentation highlights several new helper functions introduced in the
github.com/gofiber/utilsmodule, such asParseInt,ParseUint,Walk,ReadFile, andTimestamp, which were not available in the previous in-repoutils.
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 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
-
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.
Pull Request Overview
This PR documents the migration from Fiber's built-in utils package to the external github.com/gofiber/utils module for v3. The documentation provides comprehensive migration guidance including function mapping and code examples.
Key changes:
- Added utils section to the "What's New" overview with reference to migration guide
- Created detailed migration guide with function mapping table showing v2 to v3 replacements
- Included practical code examples demonstrating the migration process
There was a problem hiding this comment.
Code Review
This pull request effectively documents the migration of the utils package to an external module. The added section in whats_new.md provides a clear and comprehensive guide for users, including a function mapping table and code examples. My review identifies a few areas for improvement to ensure accuracy and readability.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
docs/whats_new.md (2)
893-898: Add a quick “how to install” tip for the external utils moduleRecommend adding an explicit go get step and noting the Go 1.25+ requirement to preempt user friction (your CI also flagged the newer Go requirement). This keeps the section self-contained and actionable.
Apply this diff to append a tip block under the first paragraph:
## 🛠️ Utils {#utils} Fiber v3 removes the built-in `utils` directory and now imports utility helpers from the separate [`github.com/gofiber/utils`](https://github.com/gofiber/utils) module. See the [migration guide](#utils-migration) for detailed replacement steps and examples. The `github.com/gofiber/utils` module also introduces new helpers like `ParseInt`, `ParseUint`, `Walk`, `ReadFile`, and `Timestamp`. + +:::tip Quick install +Make sure you’re on Go 1.25 or newer, then add the module: + +```sh +go get github.com/gofiber/utils@latest +``` +:::
1914-1991: Tighten the Utils migration section: numbering, a clarifying note, and a couple of usage examples
- The ordered list restarts at “1.” multiple times. Markdown auto-numbers, but using 1/2/3 reads cleaner in raw view.
- Add a short note explaining the mapping convention (…Bytes → utils byte helpers; string funcs → standard library) to avoid confusion when scanning the table.
- Include tiny examples for new helpers (
ParseInt,Timestamp) to show intended use at a glance.Apply this diff:
-### 🛠️ Utils {#utils-migration} +### 🛠️ Utils {#utils-migration} Fiber v3 removes the in-repo `utils` package in favor of the external [`github.com/gofiber/utils`](https://github.com/gofiber/utils) module. -1. Replace imports: +1. Replace imports: ```go - import "github.com/gofiber/fiber/v2/utils" + import "github.com/gofiber/utils"-1. Review function changes:
+2. Review function changes:
+
+Note: functions that previously ended with...Bytesmap to byte-slice helpers ingithub.com/gofiber/utils. Plain string helpers are now covered by the Go standard library (strings/bytes) where noted.
v2 function v3 replacement AssertEqualremoved; use testing libraries like stretchr/testifyToLowerBytesutils.ToLowerBytesToUpperBytesutils.ToUpperBytesTrimRightBytesutils.TrimRightTrimLeftBytesutils.TrimLeftTrimBytesutils.TrimEqualFoldBytesutils.EqualFoldUUIDutils.UUIDUUIDv4utils.UUIDv4FunctionNameutils.FunctionNameGetArgumentutils.GetArgumentIncrementIPRangeutils.IncrementIPRangeConvertToBytesutils.ConvertToBytesCopyStringutils.CopyStringCopyBytesutils.CopyBytesByteSizeutils.ByteSizeToStringutils.ToStringUnsafeStringutils.UnsafeStringUnsafeBytesutils.UnsafeBytesGetStringremoved; use utils.ToStringor the standard libraryGetBytesremoved; use utils.CopyBytesor[]byte(s)ImmutableStringremoved; strings are already immutable GetMIMEutils.GetMIMEParseVendorSpecificContentTypeutils.ParseVendorSpecificContentTypeStatusMessageutils.StatusMessageIsIPv4utils.IsIPv4IsIPv6utils.IsIPv6ToLowerutils.ToLowerToUpperutils.ToUpperTrimLeftstrings.TrimLeftTrimstrings.TrimTrimRightstrings.TrimRightEqualFoldstrings.EqualFoldStartTimeStampUpdaterutils.StartTimeStampUpdater(newutils.Timestampprovides the current value)-1. Update your code. For example:
+3. Update your code. For example:// v2 import oldutils "github.com/gofiber/fiber/v2/utils" func demo() { b := oldutils.TrimBytes([]byte(" fiber ")) id := oldutils.UUIDv4() s := oldutils.GetString([]byte("foo")) } // v3 import ( "github.com/gofiber/utils" "strings" ) func demo() { b := utils.Trim([]byte(" fiber ")) id := utils.UUIDv4() s := utils.ToString([]byte("foo")) t := strings.TrimRight("bar ", " ") }-The
github.com/gofiber/utilsmodule also introduces new helpers likeParseInt,ParseUint,Walk,ReadFile, andTimestamp.
+Thegithub.com/gofiber/utilsmodule also introduces new helpers likeParseInt,ParseUint,Walk,ReadFile, andTimestamp.
+
+go +// Examples +v, err := utils.ParseInt[int]("42") // -> 42, nil +nowUnixMilli := utils.Timestamp() // current cached unix ms (updated by StartTimeStampUpdater) +</blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used**: CodeRabbit UI **Review profile**: CHILL **Plan**: Pro **💡 Knowledge Base configuration:** - MCP integration is disabled by default for public repositories - Jira integration is disabled by default for public repositories - Linear integration is disabled by default for public repositories You can enable these sources in your CodeRabbit configuration. <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between edd70830728f4f09bcc2421dce07e7934f91fd03 and 185eaf6e0dfda33c67c71158227aaca2552b1992. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `docs/whats_new.md` (4 hunks) </details> <details> <summary>🧰 Additional context used</summary> <details> <summary>📓 Path-based instructions (1)</summary> <details> <summary>docs/**</summary> **📄 CodeRabbit inference engine (.github/copilot-instructions.md)** > Review and update the contents of the `docs` folder if necessary when modifying code Files: - `docs/whats_new.md` </details> </details><details> <summary>🧠 Learnings (3)</summary> <details> <summary>📓 Common learnings</summary>Learnt from: ckoch786
PR: #3230
File: docs/whats_new.md:944-951
Timestamp: 2024-12-15T19:56:45.935Z
Learning: Detailed usage examples and explanations for new methods likeRemoveRouteandRemoveRouteByNameare documented indocs/api/app.md, so it's unnecessary to duplicate them indocs/whats_new.md.Learnt from: ReneWerner87
PR: #3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in theTestmethod inapp.go.</details> <details> <summary>📚 Learning: 2024-11-15T07:56:21.623Z</summary>Learnt from: ReneWerner87
PR: #3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in theTestmethod inapp.go.**Applied to files:** - `docs/whats_new.md` </details> <details> <summary>📚 Learning: 2024-11-10T23:44:13.704Z</summary>Learnt from: gaby
PR: #3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In themiddleware/adaptor/adaptor.gofile of the Fiber framework, when updating context handling, replacingc.Context()withc.RequestCtx()is appropriate to access thefasthttp.RequestCtx.**Applied to files:** - `docs/whats_new.md` </details> </details> </details> </details> <details> <summary>🔇 Additional comments (2)</summary><blockquote> <details> <summary>docs/whats_new.md (2)</summary><blockquote> `27-27`: **TOC entry for Utils looks good** The anchor matches the new section id (`#utils`) introduced below. No action needed. --- `1414-1414`: **Migration guide TOC entry is correct** The link (`#utils-migration`) correctly points to the new migration subsection id below. Looks good. </blockquote></details> </blockquote></details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Summary
github.com/gofiber/utilsTesting
make audit(fails: EncodeMsg passes lock by value)make generatemake betteralign(fails: package requires newer Go version go1.25)make modernize(fails: package requires newer Go version go1.25)make formatmake testmake markdownhttps://chatgpt.com/codex/tasks/task_e_68a8e7a57d3c8326b4ae7856b0010af5