Skip to content

Add option to customize the Gorilla Mux route#810

Merged
danielgtaylor merged 3 commits into
danielgtaylor:mainfrom
RangelReale:mux-customize
May 9, 2025
Merged

Add option to customize the Gorilla Mux route#810
danielgtaylor merged 3 commits into
danielgtaylor:mainfrom
RangelReale:mux-customize

Conversation

@RangelReale

Copy link
Copy Markdown
Contributor

This MR adds an option to the Gorilla mux adapter, allowing customizing the mux route.

This allows, for example, adding standard HTTP handlers per route, maybe using huma.Operation.Metadata as input parameters.

@RangelReale

Copy link
Copy Markdown
Contributor Author

my usecase is using http.TimeoutHandler per route, it changes the ResponseWriter, so it is impossible to do with Huma middleware.

@danielgtaylor danielgtaylor requested a review from Copilot May 9, 2025 23:37

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

This PR adds an option to customize the Gorilla mux route by introducing a new Option type and a WithRouteCustomizer function.

  • Introduces WithRouteCustomizer in options.go for customizing routes.
  • Embeds the options into the gMux struct in humamux.go and applies the route customizer in the Handle method.
  • Adds tests in humagmux_test.go to verify middleware customization.

Reviewed Changes

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

File Description
adapters/humamux/options.go Adds an Option type and WithRouteCustomizer for route customization.
adapters/humamux/humamux.go Updates the gMux struct to embed options and apply route customization in Handle.
adapters/humamux/humagmux_test.go Provides tests validating the custom middleware functionality.

@codecov

codecov Bot commented May 9, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.08%. Comparing base (eb497ee) to head (73376c6).
Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #810   +/-   ##
=======================================
  Coverage   93.08%   93.08%           
=======================================
  Files          23       23           
  Lines        5307     5307           
=======================================
  Hits         4940     4940           
  Misses        314      314           
  Partials       53       53           

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

@danielgtaylor danielgtaylor left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks! 👍

@danielgtaylor danielgtaylor merged commit 21709a0 into danielgtaylor:main May 9, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants