Hi everyone,
I have a situation where I want to add middlewares to all routes except some that start with a specific pattern. This is the code I'm currently using:
r := mux.NewRouter()
r.Use(MW1)
r.Use(MW2)
r.Handle(...)
// some more handlers ...
r.Handle(...)
sub := r.PathPrefix("/static").Subrouter()
sub.Use(MW3)
sub.PathPrefix("/").Handler(http.FileServer(...)) // serve from filesystem on this route
I want to have MW3 only executed on the static route, which works perfectly fine. MW1 and MW2 should be execute everywhere BUT on the static route. Is there any way to easily achieve this?
Thanks for any help in advance