Conditional middlewares
2hamed opened this issue ยท 4 comments
2hamed commented
I though it might be a good idea to make alice be able to apply middlewares based on conditions which the Request
must satisfy.
For example some url paths need user authentication and some don't. It's a waste to apply the auth middleware to those as well.
Any idea on this?
elithrar commented
You could have middleware that determines which middleware to run based on
a pattern, which would effectively be a request router ๐
โฆOn Sun, Jul 16, 2017 at 9:19 PM Hamed Momeni ***@***.***> wrote:
I though it might be a good idea to make alice be able to apply
middlewares based on conditions which the Request must satisfy.
For example some url paths need user authentication and some don't. It's a
waste to apply the auth middleware to those as well.
Any idea on this?
โ
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#39>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABIcLdbXqXS5jM94p2eYSH22qyAu9DNks5sOuDkgaJpZM4OZiU3>
.
2hamed commented
Well I'm using gorilla/mux as my router. I can't imagine how should I
proceed from there?!
On Mon, Jul 17, 2017 at 9:00 AM, Matt Silverlock <notifications@github.com>
wrote:
โฆ You could have middleware that determines which middleware to run based on
a pattern, which would effectively be a request router ๐
On Sun, Jul 16, 2017 at 9:19 PM Hamed Momeni ***@***.***>
wrote:
> I though it might be a good idea to make alice be able to apply
> middlewares based on conditions which the Request must satisfy.
> For example some url paths need user authentication and some don't. It's
a
> waste to apply the auth middleware to those as well.
>
> Any idea on this?
>
> โ
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <#39>, or mute the thread
> <https://github.com/notifications/unsubscribe-auth/
AABIcLdbXqXS5jM94p2eYSH22qyAu9DNks5sOuDkgaJpZM4OZiU3>
> .
>
โ
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#39 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAgzsg8Qqcki17ow-seJhNtOdipZwtTNks5sOuNMgaJpZM4OZiU3>
.
--
Hamed Momeni
CTO @ Arioo.com
justinas commented
Hi @2hamed,
Try something like this:
r := mux.NewRouter()
r.Handle("/about", alice.New(middleware1, middleware2).Then(aboutPage))
r.Handle("/contact", alice.New(middleware3, middleware4).Then(contactPage))
Gorilla mux can also match on headers, query values, etc., so this approach is pretty flexible.
2hamed commented
Awesome, thanks.