-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🚀 [Feature]: v3 Router interface change #2160
Comments
I think current interface is simple and cleaner. We also aim to be compatible with Express.js in most cases. What do you think @ReneWerner87 |
I think the proposed interface is clearer in terms of what the developer's trying to achieve. |
I have observed that other frameworks such as Gin and Hertz have similar routing interface with Fiber. What are the key reasons to think the proposed interface is clearer for developer? |
Let's say you have a handler. A handler's job is to produce a response. The current interface is a bit confusing in terms of what is happening behind the scenes.
Therefore,
i.e.
This is how laravel (possibly the most popular web framework) does it: https://laravel.com/docs/9.x/middleware#assigning-middleware-to-routes Route::get('/profile', function () {
// handler
})->middleware('auth'); // adding optional middleware
Route::get('/', function () {
// handler
})->middleware(['first', 'second']);
use App\Http\Middleware\EnsureTokenIsValid;
Route::get('/profile', function () {
// handler
})->middleware(EnsureTokenIsValid::class); Look at how cleaner that looks compared to below: Laravel also allows the less preferred way (they don't even document it anymore): Route::get('/',['middlware' => 'auth', function () {
// handler Code goes here
}]);
Route::get('/', ['middleware' => ['first', 'second'], function () {
// handler Code goes here
}]); |
i like some parts of the idea changing the parameter structure, so that for the methods where a handler is really always needed, there is also a fixed handler in the method declaration I find very good also the idea with the add with multiple methods otherwise i miss some methods in the router interface for the new version, like the USE and GROUP method |
Personal thoughts: With the proposed change it will be strange to figure out how to migrate to fiber. Imagine comming from gin, echo or another one (express maybe) with Real Discussion:
I think currently interface is good, simple and easy to understand. The current interface has same methods as others frameworks and also it's pretty simillar to express (as the philosophy of this project)
Yes, many frameworks works in this way in many languages like C#, Java, Javascript... The only exception is php. So the big question is, "what is a middleware?" Middleware is software that's assembled into an app pipeline to handle requests and responses. Each component:
And we have And It could be easly translated to code as following: app.Get("/", mw1, mw2, mw3) The main problem of new developers is think that a handler and middleware are different, but they are pretty much the same. |
@mirusky
This signature encourages better practice. i.e. Use |
I think it's better idea to do it slice. It may increase |
Hi. You can create a PR on |
Assign to me |
Done |
Idk, MIDDLEware is something in the middle, how that semantics are better than the actual one? Just because the php framework does, doesn't means thats better. As I said before: Is cleaner to read and figure out the flow path using Imagine a novice reading and thinking that handler is executed before the mw1 and mw2. If we gonna follow any framework semantics why not use the most common pattern in the principal languages ? |
Just some points:
When the coder sees the parameter name:
|
Maybe I'm little late, but I opened a survey in Reddit. Asked opinion about it and they like the current style with The time I'm writing was 217 votes. 116 v2 style and 101 v3 style. In the entire survey v2 style was ahead. People also suggested using some kind of "decorator" like: Get(route, handler).With(middlewares...) The survey could be found here |
Awesome survey: This comment was one of the reasons for my proposal: https://www.reddit.com/r/golang/comments/yj9ah8/comment/iuopr8w/?utm_source=reddit&utm_medium=web2x&context=3 |
Yeah, there's misunderstanding about it. Of course it's not clear for someone who doesn't use the fiber. But as someone said, our codebase may have a different experience and understanding about it. |
We created voting in Fiber's discord server https://discord.com/channels/704680098577514527/848707314180423750/1037295391336583220 |
It would have been good if my reasoning for the change was provided before people voted. Perhaps a link to this page. |
Feature Description
v2 definition:
v3 definition:
It would be good if the signature could be changed for these:
Secondly,
OR alternatively,
method string
interprets methods with pipes: eg."GET|POST"
Additional Context (optional)
It will be operationally equivalent to (but cleaner):
Code Snippet (optional)
No response
Checklist:
The text was updated successfully, but these errors were encountered: