Refactor Chain function to use Middleware type#1090
Refactor Chain function to use Middleware type#109072sevenzy2 wants to merge 5 commits intogo-chi:masterfrom
Conversation
|
I actually had a similar change locally and was considering PRing it, one fairly important different is I made it a type alias rather than a wholly different type so existing code would keep working, I also defined it just before the +// Middlware is a type alias to standard middleware handlers.
+type Middleware = func(http.Handler) http.Handler
+
// Middlewares type is a slice of standard middleware handlers with methods
// to compose middleware chains and http.Handler's.
-type Middlewares []func(http.Handler) http.Handler
+type Middlewares []MiddlewareAfter that there's a few more places that can be updated to use it like the Router interface, WalkFunc, etc. Just search and replace! Not sure if such a change is wanted but it definitely gets my vote for being more readable, so long as it's just a type alias and therefore won't require explicit conversion from existing callers! |
|
Thats actually smart, I never thought about that, thanks for giving me a heads up. |
|
I was always hoping for Middleware type to be defined in I don't think chi is the right place to reinvent this, though. |
|
Oh I see. |
Added type alias for Middleware and Middlewares.
Removed type alias for Middleware and Middlewares.
Add middleware type to slightly enhance readability.