I think that there is a behavior that can be improved.
First, i'd like to known if that behavior is wanted.
Consider the following code:
package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/context"
)
func main() {
app := iris.New()
app.Get("/path1.txt", func(ctx context.Context) {
ctx.Text("PATH1")
})
app.Use(func(ctx context.Context) {
ctx.Text("MIDDLEWARE\n")
ctx.Next()
})
app.Get("/path2.txt", func(ctx context.Context) {
ctx.Text("PATH2")
})
app.Run(iris.Addr(":8080"))
}
With curl http://localhost:8080/path2.txt ; echo
, we have:
Okay.
But, with curl http://localhost:8080/path1.txt ; echo
, we have:
I understand why. That's cause the middleware is defined after "/path1.txt" route.
But even if it could be weird, i expected
Was it wanted by you? I can understand this way for configuring the server.
The reason why i expected
is a question of design.
The configurators are powerful to configure the server cause thet can be considered as plugin for example by making: app.Configure(plugin1, plugin2, ...)
, we have the choice to add securities, redirections, authentications, etc. or not.
It can arrive that in a configurator we can add routes but these routes must have managements defined in another configurator, even if it appears after in the configurator list.
I know how to implements this way to use middleware. Even more, i can add easily a parameter somewhere to activate this behavior. So the developer have the choice to use or not and then we have the old behavior.
I can send a PR for that. Cause the solution is simple. Today, when we make a route, the handler list is copied in the new route, so every route has its own copy of handler list. Instead of doing a copy, we should have a reference to a common handler list in the route.