Skip to content

🔥 feat: Add support for configuring the Regex engine on the router - #4254

Merged
ReneWerner87 merged 25 commits into
mainfrom
claude/add-alternative-regex-support
May 21, 2026
Merged

ReneWerner87 merged 25 commits into
mainfrom
claude/add-alternative-regex-support

Conversation

@Claude

@Claude Claude AI commented May 4, 2026

Copy link
Copy Markdown
Contributor

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.


This section details on the original issue you should resolve

<issue_title>📝 [Proposal]: ability to use alternative regex for router</issue_title>
<issue_description>### Feature Proposal Description

This is a substantially faster assembly optimised regex package that is drop in replacement: https://github.com/coregx/coregex

Alignment with Express API

Na

HTTP RFC Standards Compliance

Na

API Stability

Na

Feature Examples

Na

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have searched for existing issues that describe my proposal before opening this one.
  • I understand that a proposal that does not meet these guidelines may be closed without explanation.</issue_description>

Comments on the Issue (you are @claude[agent] in this section)

@Claude Claude AI assigned Claude and gaby May 4, 2026
@Claude Claude AI linked an issue May 4, 2026 that may be closed by this pull request
3 tasks
@ReneWerner87 ReneWerner87 added this to v3 May 4, 2026
@ReneWerner87 ReneWerner87 added this to the v3 milestone May 4, 2026
- Created RegexEngine and RegexCompiler interfaces
- Updated path.go to use configured regex engine
- Added RegexEngine field to Config with DefaultRegexEngine
- Updated router.go to pass RegexEngine to parseRoute
- Added comprehensive tests for regex abstraction
- Created example showing how to integrate coregex

Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/3e2b7990-e9c5-41f6-afbf-ad29c8bbcfd0

Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
@codecov

codecov Bot commented May 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.83051% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.33%. Comparing base (f3a2ddc) to head (80078d8).

Files with missing lines Patch % Lines
path.go 89.09% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4254      +/-   ##
==========================================
+ Coverage   91.28%   91.33%   +0.04%     
==========================================
  Files         132      132              
  Lines       13040    13087      +47     
==========================================
+ Hits        11904    11953      +49     
+ Misses        718      716       -2     
  Partials      418      418              
Flag Coverage Δ
unittests 91.33% <89.83%> (+0.04%) ⬆️

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.

Claude AI and others added 2 commits May 4, 2026 23:03
- Added regex-engines.md guide with coregex integration examples
- Documented RegexEngine and RegexCompiler interfaces
- Included performance benchmarks and use cases
- Added custom implementation examples

Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/3e2b7990-e9c5-41f6-afbf-ad29c8bbcfd0

Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
Claude finished work on behalf of gaby May 4, 2026 23:06
@Claude
Claude AI requested a review from gaby May 4, 2026 23:06
@gaby

gaby commented May 4, 2026

Copy link
Copy Markdown
Member

@claude[agent]

  • fix markdownlint issues
  • remove examples folder

- Removed examples/regex-engine folder as requested
- Updated docs/guide/regex-engines.md to remove reference to examples folder
- All markdown linting issues resolved

Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/9e71d891-0cc3-4786-8921-d994e500db6f

Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
@Claude

Claude AI commented May 4, 2026

Copy link
Copy Markdown
Contributor Author

@claude[agent]

  • fix markdownlint issues
  • remove examples folder

Fixed in d7629bf:

  • Removed examples/regex-engine folder
  • Fixed markdown linting issues in docs/guide/regex-engines.md
  • All markdown lint checks now pass

Claude finished work on behalf of gaby May 4, 2026 23:29
@gaby

gaby commented May 5, 2026

Copy link
Copy Markdown
Member

@claude[agent] I'm not sure about the addition of regex.go. It seems like it might be over-engineered.

I believe the approach should be as straightforward as our JSONEncoder and Decoder implementations within the app configuration.

Moved regex types from separate regex.go file into path.go where they are used. This follows the simpler pattern similar to JSONEncoder/Decoder and reduces over-engineering by keeping related code together.

Changes:
- Removed regex.go and moved RegexEngine/RegexCompiler types to path.go
- Moved tests from regex_test.go to path_test.go
- All tests pass, no linting issues

Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/175129f3-3f03-4a29-9673-b0521797d587

Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
@Claude

Claude AI commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

@claude[agent] I'm not sure about the addition of regex.go. It seems like it might be over-engineered.

I believe the approach should be as straightforward as our JSONEncoder and Decoder implement...

Simplified in ffc10c3. Removed the separate regex.go file and moved all regex types directly into path.go where they're actually used. This follows a simpler pattern similar to other encoders/decoders and keeps related code together. The abstraction is now more minimal while still providing the flexibility to use alternative regex engines.

Claude finished work on behalf of gaby May 5, 2026 02:11
@gaby

gaby commented May 5, 2026

Copy link
Copy Markdown
Member

@claude[agent] Looking at the guide docs/guide/regex-engines.md and code. Using a different regex library is too complicated. We can simplify this.

Following feedback to simplify the regex engine abstraction, this commit
refactors the implementation to use a simple function type instead of
interface-based approach.

Key changes:
- Replace RegexEngine interface with RegexHandler function type
- RegexHandler is now: func(pattern string) RegexCompiler
- Add defaultRegexHandler function that wraps regexp.MustCompile
- Update all references from RegexEngine to RegexHandler
- Simplify documentation to show direct usage without adapter types

This follows the same pattern as JSONEncoder/JSONDecoder in the codebase,
making it much simpler for users to adopt alternative regex engines:

Before (required adapter types):
    type CoregexEngine struct{}
    func (CoregexEngine) MustCompile(pattern string) fiber.RegexCompiler {...}
    app := fiber.New(fiber.Config{RegexEngine: CoregexEngine{}})

After (just a function):
    app := fiber.New(fiber.Config{
        RegexHandler: func(pattern string) fiber.RegexCompiler {
            return coregex.MustCompile(pattern)
        },
    })

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
Claude finished work on behalf of gaby May 5, 2026 02:40
@gaby

gaby commented May 5, 2026

Copy link
Copy Markdown
Member

@claude[agent] Why are you adding a handler, instead of just using coregex.MustCompile. Stdlib and coregex use the same API.

// stdlib
re := regexp.MustCompile(pattern)

// coregex — same API
re := coregex.MustCompile(pattern)

The app config option should just take coregex.MustCompile, i think?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Comment thread path.go Outdated
Comment thread path.go Outdated
Comment thread router.go
Comment thread path_test.go Outdated
Comment thread docs/guide/regex-engines.md Outdated
Copilot finished work on behalf of gaby May 21, 2026 12:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (3)

path_test.go:577

  • Use Fiber status constants (e.g., StatusOK / StatusNotFound) instead of numeric literals to match the conventions used elsewhere in this test file.
	require.Equal(t, 404, resp.StatusCode)

path_test.go:650

  • Use StatusOK instead of the numeric literal 200 for consistency with other tests in this file.
	require.Equal(t, 200, resp.StatusCode)

path_test.go:670

  • Use StatusOK/StatusNotFound instead of numeric literals (200/404) for consistency with other tests in this file.
	require.Equal(t, 200, resp.StatusCode)

	resp, err = app.Test(httptest.NewRequest(http.MethodGet, "/date/2024-1-5", http.NoBody))
	require.NoError(t, err)
	require.Equal(t, 404, resp.StatusCode)

Comment thread path_test.go Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comment thread path.go Outdated
Comment thread path.go Outdated
@gaby

gaby commented May 21, 2026

Copy link
Copy Markdown
Member

@copilot fix markdownlint issues

Copilot AI commented May 21, 2026

Copy link
Copy Markdown
Contributor

@claude[agent]

  • fix markdownlint issues
  • remove examples folder

Addressed in 80078d8. markdownlint is clean now, and there isn’t an examples folder left in the current PR diff.

@claude[agent] I'm not sure about the addition of regex.go. It seems like it might be over-engineered.

I believe the approach should be as straightforward as our JSONEncoder and Decoder implement...

Addressed in 80078d8. I simplified the public surface so the feature is documented and exposed more directly instead of surfacing extra helper types.

@claude[agent] Looking at the guide docs/guide/regex-engines.md and code. Using a different regex library is too complicated. We can simplify this.

Addressed in 80078d8. The guide and API docs now present this as a straightforward RegexHandler: coregex.MustCompile / regexp.MustCompile configuration.

@claude[agent] Why are you adding a handler, instead of just using coregex.MustCompile. Stdlib and coregex use the same API.

// stdlib
...

Addressed in 80078d8. The config now stays focused on assigning coregex.MustCompile or regexp.MustCompile directly, and the docs/API wording were simplified around that usage.

@copilot fix markdownlint issues

Fixed in 80078d8. markdownlint passes on the updated branch.

Copilot finished work on behalf of gaby May 21, 2026 15:12
@ReneWerner87
ReneWerner87 merged commit ee0c55a into main May 21, 2026
20 of 21 checks passed
@github-project-automation github-project-automation Bot moved this to Done in v3 May 21, 2026
@welcome

welcome Bot commented May 21, 2026

Copy link
Copy Markdown

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

@ReneWerner87
ReneWerner87 deleted the claude/add-alternative-regex-support branch May 21, 2026 15:58
@ReneWerner87 ReneWerner87 modified the milestones: v3, v3.3.0 May 22, 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.

📝 [Proposal]: ability to use alternative regex for router

5 participants