feat: [#970] support withoutMiddleware similar to Laravel#1497
feat: [#970] support withoutMiddleware similar to Laravel#1497u-wlkjyy wants to merge 2 commits into
Conversation
- Add ExcludedMiddleware field to contracts/http.Info - Add WithoutMiddleware method to contracts/route.Action interface This allows routes to exclude specific middleware, similar to Laravel's withoutMiddleware() method. Useful for webhook endpoints, public APIs, and routes that need to bypass auth/throttling from protected groups.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1497 +/- ##
==========================================
- Coverage 69.46% 69.46% -0.01%
==========================================
Files 378 378
Lines 29723 29726 +3
==========================================
+ Hits 20648 20649 +1
- Misses 8123 8124 +1
- Partials 952 953 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
hwbrzzl
left a comment
There was a problem hiding this comment.
Thanks for the PR. Please run go tool mockery to generate the latest mock files. And could you implement this style Route::withoutMiddleware([EnsureTokenIsValid::class])->group as well?
| Method string `json:"method"` | ||
| Name string `json:"name"` | ||
| Path string `json:"path"` | ||
| ExcludedMiddleware []Middleware `json:"excluded_middleware,omitempty"` |
There was a problem hiding this comment.
It's unnecessary for now, given Middleware doesn't exist as well.
- Add WithoutMiddleware method to Router interface for group-level exclusion - Regenerate mocks via go tool mockery - This enables Route.WithoutMiddleware(...).Group(...) style similar to Laravel
|
Thanks for the review! I've addressed both points:
facades.Route().Middleware(authMiddleware).WithoutMiddleware(authMiddleware).Group(func(router route.Router) {
router.Get("/dashboard", DashboardController.Index)
})This excludes the middleware for all routes registered within the group. The gin driver implementation is in goravel/gin#229. |
|
Note on the The build errors confirm exactly this: This requires coordinated merging:
The gin driver implementation is ready at goravel/gin#229. I can also open a |
Yes, it's fine to ignore the test-in-example failure in this PR. |
Description
This PR adds support for the
WithoutMiddlewaremethod to routes, similar to Laravel'swithoutMiddleware()functionality. This allows routes to exclude specific middleware that would otherwise be applied via route groups.Changes
Framework Contracts
ExcludedMiddlewarefield tocontracts/http/request.goInfo structWithoutMiddlewaremethod tocontracts/route/route.goAction interfaceUsage Example
Use Cases
Related Issue
Fixes #970
Note
The gin driver implementation will be submitted as a separate PR after this one is merged.