Improve middleware func with filter of type string#1
Improve middleware func with filter of type string#1pengdst wants to merge 5 commits intoQiscus-Integration:mainfrom
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.
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.
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