-
Notifications
You must be signed in to change notification settings - Fork 1
Improve middleware func with filter of type string #1
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
base: main
Are you sure you want to change the base?
Conversation
- middleware now can receive multiple filter with type string (optional) - middleware filter with function now renamed to MiddlewareFunc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @pengdst thanks for your PR
But, the idea of using function parameters with a return bool makes it easier for developers to customize filter conditions using the echo context property. Your suggested new middleware can also be easily implemented using this approach:
r.Use(echolog.Middleware(func(c echo.Context) (skip bool) {
for _, path := range []string{"/healthcheck", "/foo"} {
if path == c.Request().RequestURI {
skip = true
break
}
}
return
}))|
The developer also able to use that way, i just rename the function to MiddlewareFilterFunc. The difference is when developers don't filter they don't need to add 'nil' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update @syahidfrd : i just rename the function Middleware() to Default() and MiddlewareFilterFunc to Middleware.
So, now for simple usecase developers can do this way
e.Use(echolog.Default())
or to add filter
e.Use(echolog.Default("/healthcheck", "foo", "bar"))
Also, for advance filter usecase, they can do this too:
r.Use(echolog.Middleware(func(c echo.Context) (skip bool) {
for _, path := range []string{"/healthcheck", "/foo"} {
if path == c.Request().RequestURI {
skip = true
break
}
}
return
}))
I think create new function Default is better than rename the Middleware function from my previous commit. How do you think?
Hi @pengdst I don't quite agree, the filter function is not just for filtering URIs, but more than that, developers can use the echo context to get header data, host, IP address etc. for filtering. |
Improve middleware filter functionality
menyederhanakan apply filter middleware dengan function Default() untuk simple usecase
apply filter menggunakan variadic functions dengan arguments type string
apply filter function arguments dapat dikosongkan (optional) karena menggunakan variadic functions
update README.md
atau