diff --git a/_examples/routing/dynamic-path/same-pattern-different-func/main.go b/_examples/routing/dynamic-path/same-pattern-different-func/main.go new file mode 100644 index 00000000..e241a51b --- /dev/null +++ b/_examples/routing/dynamic-path/same-pattern-different-func/main.go @@ -0,0 +1,33 @@ +package main + +import "github.com/kataras/iris/v12" + +func main() { + app := newApp() + app.Logger().SetLevel("debug") + app.Listen(":8080") +} + +func newApp() *iris.Application { + app := iris.New() + + app.HandleMany(iris.MethodGet, "/ /api/{page:string suffix(.html)}", handler1) + app.Get("/api/{name:string suffix(.zip)}", handler2) + + return app +} + +func handler1(ctx iris.Context) { + reply(ctx) +} + +func handler2(ctx iris.Context) { + reply(ctx) +} + +func reply(ctx iris.Context) { + ctx.JSON(iris.Map{ + "handler": ctx.HandlerName(), + "params": ctx.Params().Store, + }) +} diff --git a/_examples/routing/dynamic-path/same-pattern-different-func/main_test.go b/_examples/routing/dynamic-path/same-pattern-different-func/main_test.go new file mode 100644 index 00000000..1e99dd6c --- /dev/null +++ b/_examples/routing/dynamic-path/same-pattern-different-func/main_test.go @@ -0,0 +1,41 @@ +package main + +import ( + "testing" + + "github.com/kataras/iris/v12/core/memstore" + "github.com/kataras/iris/v12/httptest" +) + +func TestSameParameterTypeDifferentMacroFunctions(t *testing.T) { + app := newApp() + e := httptest.New(t, app) + + type resp struct { + Handler string `json:"handler"` + Params memstore.Store `json:"params"` + } + + var ( + expectedIndex = resp{ + Handler: "iris/_examples/routing/dynamic-path/same-pattern-different-func.handler1", + Params: nil, + } + expectedHTMLPage = resp{ + Handler: "iris/_examples/routing/dynamic-path/same-pattern-different-func.handler1", + Params: memstore.Store{ + {Key: "page", ValueRaw: "random.html"}, + }, + } + expectedZipName = resp{ + Handler: "iris/_examples/routing/dynamic-path/same-pattern-different-func.handler2", + Params: memstore.Store{ + {Key: "name", ValueRaw: "random.zip"}, + }, + } + ) + + e.GET("/").Expect().Status(httptest.StatusOK).JSON().Equal(expectedIndex) + e.GET("/api/random.html").Expect().Status(httptest.StatusOK).JSON().Equal(expectedHTMLPage) + e.GET("/api/random.zip").Expect().Status(httptest.StatusOK).JSON().Equal(expectedZipName) +}