Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refactor: update utils and add go 1.26 for test workflow#4087

Merged
ReneWerner87 merged 2 commits intomainfrom
update_utils_and_go
Feb 16, 2026
Merged

refactor: update utils and add go 1.26 for test workflow#4087
ReneWerner87 merged 2 commits intomainfrom
update_utils_and_go

Conversation

@ReneWerner87
Copy link
Member

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 14, 2026

Walkthrough

This PR replaces broad github.com/gofiber/utils/v2 usage with targeted subpackages (utils/v2/bytes and utils/v2/strings) across many files, switching various ToLower/ToUpper calls to the specialized, performance-oriented helpers. It also adds three generic accessors in req.go (Locals, Query, Params).

Changes

Cohort / File(s) Summary
Core framework
bind.go, ctx.go, path.go, redirect.go, router.go, services.go, helpers.go
Switched imports to utils/v2/bytes (utilsbytes) and/or utils/v2/strings (utilsstrings) and replaced general utils lower/uppercasing calls with the specialized variants (UnsafeToLower, ToLower, ToUpper, etc.).
Request handling
req.go
Replaced various lower/uppercasing calls with utilsbytes/utilsstrings variants and added three generic public helpers: Locals[V any], Query[V GenericType], and Params[V GenericType].
Binder/mapping
binder/mapping.go
Replaced utils.ToLower usages with utilsstrings.ToLower for normalization and field extraction.
Client cookies
client/cookiejar.go
Introduced utilsbytes and utilsstrings; replaced host/domain lowercasing with UnsafeToLower/ToLower variants across cookie parsing and matching logic.
Middleware
middleware/cache/cache.go, middleware/cors/cors.go, middleware/cors/utils.go, middleware/csrf/csrf.go, middleware/csrf/helpers.go, middleware/idempotency/idempotency.go
Swapped utils import for utils/v2/strings alias and updated header/scheme/host normalization calls to use utilsstrings.ToLower / related helpers.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • gaby
  • sixcolors
  • efectn

Poem

🐰 I hopped through imports, neat and spry,

bytes and strings now split and high,
Generics tucked in, typed and clean,
Lowercases faster — a rabbit's dream! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided by the author, but the template requires a detailed description including changes introduced, type of change, and pre-submission checklist completion. Add a comprehensive description explaining the refactoring scope, the benefits of updating to subpackage imports, any performance implications, and confirmation that existing tests pass with these changes.
Docstring Coverage ⚠️ Warning Docstring coverage is 56.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'refactor: update utils and add go 1.26 for test workflow' accurately describes the main changes, which involve refactoring utility imports across multiple files and updating the test workflow.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch update_utils_and_go

No actionable comments were generated in the recent review. 🎉


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

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 primarily refactors the project's usage of the gofiber/utils/v2 package. It transitions from a general utils import to more specialized utils/v2/bytes and utils/v2/strings sub-packages. This change enhances code organization and leverages optimized utility functions for byte and string manipulations, improving maintainability and potentially performance. The update also includes a minor version bump for the gofiber/utils/v2 dependency.

Highlights

  • Refactored Utility Imports: The project's dependency on the monolithic github.com/gofiber/utils/v2 package has been refactored to use more specific sub-packages: github.com/gofiber/utils/v2/bytes and github.com/gofiber/utils/v2/strings. This improves modularity and clarifies the intent of string and byte manipulations.
  • Updated Utility Function Calls: Existing calls to general utility functions like utils.ToLower and utils.ToLowerBytes have been replaced with their specialized counterparts, such as utilsstrings.ToLower for string conversions and utilsbytes.UnsafeToLower for byte slice conversions, across numerous files.
  • Dependency Version Bump: The go.mod and go.sum files have been updated to reflect the new version of the gofiber/utils/v2 dependency, now at v2.0.2.
  • Removed Outdated Comment: An outdated comment in helpers.go warning about utils.ToLowerBytes causing a panic was removed, indicating that the new utilsbytes.UnsafeToLower function likely addresses or bypasses the previous concern.
Changelog
  • bind.go
    • Imported utilsbytes package.
    • Updated content type conversion to use utilsbytes.UnsafeToLower.
  • binder/mapping.go
    • Imported utilsstrings package.
    • Updated field name and key conversions to use utilsstrings.ToLower or utilsstrings.UnsafeToLower.
  • client/cookiejar.go
    • Imported utilsbytes and utilsstrings packages.
    • Updated host and domain string conversions to use specialized ToLower functions.
  • ctx.go
    • Imported utilsbytes package.
    • Updated path lowercasing for case-insensitive routing to use utilsbytes.UnsafeToLower.
  • go.mod
    • Updated github.com/gofiber/utils/v2 dependency to v2.0.2.
  • go.sum
    • Updated checksums for github.com/gofiber/utils/v2 to v2.0.2.
  • helpers.go
    • Imported utilsbytes package.
    • Removed a comment about ToLowerBytes causing a panic.
    • Updated header parameter key conversion to utilsbytes.UnsafeToLower.
  • middleware/cache/cache.go
    • Imported utilsstrings package.
    • Updated Vary header parsing to use utilsstrings.ToLower.
  • middleware/cors/cors.go
    • Imported utilsstrings package.
    • Updated Origin header conversion to use utilsstrings.ToLower.
  • middleware/cors/utils.go
    • Imported utilsstrings package.
    • Updated origin normalization to use utilsstrings.UnsafeToLower for scheme and host.
  • middleware/csrf/csrf.go
    • Imported utilsstrings package.
    • Updated Sec-Fetch-Site, Origin, and Referer header validations to use utilsstrings.UnsafeToLower.
  • middleware/csrf/helpers.go
    • Imported utilsstrings package.
    • Updated scheme and host normalization functions to use utilsstrings.UnsafeToLower.
  • middleware/idempotency/idempotency.go
    • Imported utilsstrings package.
    • Updated response header key processing to use utilsstrings.ToLower.
  • path.go
    • Imported utilsbytes and utilsstrings packages.
    • Updated path and pattern lowercasing for routing to use specialized ToLower functions.
  • redirect.go
    • Imported utilsbytes package.
    • Updated content type conversion for old input handling to use utilsbytes.UnsafeToLower.
  • req.go
    • Imported utilsbytes and utilsstrings packages.
    • Updated various request header, method, scheme, range, and subdomain string/byte conversions to use specialized utility functions.
  • router.go
    • Imported utilsstrings package.
    • Updated path normalization and HTTP method conversions to use utilsstrings.ToLower or utilsstrings.UnsafeToUpper.
  • services.go
    • Imported utilsstrings package.
    • Updated service state logging to use utilsstrings.UnsafeToUpper.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/test.yml
Activity
  • No human activity has been recorded on this pull request yet.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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

  1. 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 updates the gofiber/utils dependency and refactors the code to use its new subpackages. The changes are generally well-executed and include a nice bug fix in services.go. However, I've identified a significant issue in helpers.go where an unsafe function is used on a temporary byte slice, which could lead to memory corruption. Please see my detailed comment on that.

Copy link
Contributor

Copilot AI left a 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 the codebase to use specific subpackages from gofiber/utils/v2 (strings and bytes) instead of the top-level package, updates the utils dependency from v2.0.1 to v2.0.2, and adds Go 1.26 to the test workflow matrix.

Changes:

  • Migrated from utils.ToLower/ToUpper/ToLowerBytes to subpackage-specific functions like utilsstrings.ToLower/UnsafeToLower and utilsbytes.UnsafeToLower
  • Updated gofiber/utils/v2 dependency from v2.0.1 to v2.0.2 in go.mod and go.sum
  • Added Go 1.26.x to the GitHub Actions test matrix alongside Go 1.25.x

Reviewed changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
services.go Updated to use utilsstrings.UnsafeToUpper for service state logging, removed redundant ToUpper call
router.go Replaced utils.ToLower/ToUpper with utilsstrings.ToLower/UnsafeToUpper for path normalization and HTTP method handling
req.go Updated string and byte operations to use utilsstrings and utilsbytes subpackages for content encoding, method override, scheme, range, and subdomain handling
redirect.go Changed content-type header processing to use utilsbytes.UnsafeToLower
path.go Updated route pattern matching to use utilsbytes.UnsafeToLower and utilsstrings.ToLower
middleware/idempotency/idempotency.go Simplified header name lowercasing by using utilsstrings.ToLower without CopyString wrapper, but comment is now outdated
middleware/csrf/helpers.go Updated scheme and host normalization to use utilsstrings.UnsafeToLower
middleware/csrf/csrf.go Changed origin and referer header processing to use utilsstrings.UnsafeToLower
middleware/cors/utils.go Updated origin normalization to use utilsstrings.UnsafeToLower
middleware/cors/cors.go Changed origin header processing to use utilsstrings.ToLower
middleware/cache/cache.go Updated Vary header parsing to use utilsstrings.ToLower
helpers.go Removed outdated comment about unsafe byte usage and updated to use utilsbytes.UnsafeToLower
ctx.go Updated path detection to use utilsbytes.UnsafeToLower
client/cookiejar.go Attempted to update domain processing to use utilsbytes.UnsafeToLower, but missing return value assignment (bug)
binder/mapping.go Updated field name handling to use utilsstrings.ToLower and utilsstrings.UnsafeToLower
bind.go Changed content-type processing to use utilsbytes.UnsafeToLower
go.mod Updated gofiber/utils/v2 dependency from v2.0.1 to v2.0.2
go.sum Updated checksums for gofiber/utils/v2 v2.0.2
.github/workflows/test.yml Added Go 1.26.x to test matrix

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
middleware/idempotency/idempotency.go (1)

58-63: ⚠️ Potential issue | 🔴 Critical

Remove stale comment and restore utils.CopyString to fix a correctness bug.

The utilsstrings.ToLower function uses UnsafeString internally when converting uppercase characters, returning a string backed by a temporary []byte. Storing such an unsafe string as a map key is a correctness bug because the backing memory can be reused after the function returns, corrupting the map key.

The original code with CopyString was correct. Removing it introduced a subtle correctness issue. The comment is stale, but it pointed to a real problem.

Required fix
 	keepResponseHeadersMap := make(map[string]struct{}, len(cfg.KeepResponseHeaders))
 	for _, h := range cfg.KeepResponseHeaders {
-		// CopyString is needed because utils.ToLower uses UnsafeString
-		// and map keys must be immutable
-		keepResponseHeadersMap[utilsstrings.ToLower(h)] = struct{}{}
+		keepResponseHeadersMap[utils.CopyString(utilsstrings.ToLower(h))] = struct{}{}
 	}
🤖 Fix all issues with AI agents
In `@bind.go`:
- Line 295: The current call in the bind logic constructs ctype using
utils.UnsafeString(utilsbytes.UnsafeToLower(b.ctx.RequestCtx().Request.Header.ContentType())),
but utilsbytes.UnsafeToLower mutates the provided byte slice in-place (which
here is the header's internal buffer returned by
b.ctx.RequestCtx().Request.Header.ContentType()); verify whether mutating the
stored Content-Type is intentional, and if the original header casing must be
preserved replace UnsafeToLower with utilsbytes.ToLower (which returns a new
slice) while still converting to string via utils.UnsafeString, or explicitly
copy the header bytes before calling UnsafeToLower so downstream readers of
Header.ContentType() are unaffected.

In `@helpers.go`:
- Line 565: The code stores a map key using a string created from a
fasthttp-owned buffer via utils.UnsafeString(utilsbytes.UnsafeToLower(key)),
which is unsafe because the underlying buffer can be mutated; change the
creation of lowerKey in the VisitHeaderParams handling to make an owned, safe
lowercase string (e.g., convert the slice to a new string and apply
strings.ToLower or copy the bytes before using UnsafeString) so map keys are not
backed by fasthttp's mutable buffer; update the lowerKey assignment (referencing
lowerKey, VisitHeaderParams, utilsbytes.UnsafeToLower, utils.UnsafeString)
accordingly.

In `@redirect.go`:
- Line 193: The code mutates fasthttp's internal Content-Type buffer by calling
utilsbytes.UnsafeToLower on the header bytes; instead avoid in-place mutation by
converting to a safe string and lowercasing that (or cloning the bytes first).
Replace the UnsafeToLower usage when computing ctype in redirect.go with a
non-mutating call such as
utils.ToLower(utils.UnsafeString(r.c.RequestCtx().Request.Header.ContentType()))
or by copying the header bytes (e.g., make/clone) before calling
utilsbytes.UnsafeToLower so downstream reads (middleware, logs) are not
affected; update references around the variable ctype and usages in
WithInput()/Body() accordingly.

@codecov
Copy link

codecov bot commented Feb 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.08%. Comparing base (5628312) to head (b84d1ac).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4087      +/-   ##
==========================================
- Coverage   91.08%   91.08%   -0.01%     
==========================================
  Files         119      119              
  Lines       11303    11302       -1     
==========================================
- Hits        10295    10294       -1     
  Misses        637      637              
  Partials      371      371              
Flag Coverage Δ
unittests 91.08% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@gaby gaby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ReneWerner87 ReneWerner87 merged commit 6b75c82 into main Feb 16, 2026
20 checks passed
@ReneWerner87 ReneWerner87 deleted the update_utils_and_go branch February 16, 2026 09:12
@github-project-automation github-project-automation bot moved this to Done in v3 Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants