Former-commit-id: d95be1456a78fbafd7ec5fec22f2066454eb76c6
This commit is contained in:
Gerasimos (Makis) Maropoulos 2019-03-01 14:10:07 +02:00
parent 444a4a0363
commit df3a68255c
3 changed files with 25 additions and 11 deletions

View File

@ -7,7 +7,7 @@ import (
"github.com/kataras/iris/context"
)
// def is the default herp value which can be used for dependencies share.
// def is the default hero value which can be used for dependencies share.
var def = New()
// Hero contains the Dependencies which will be binded

View File

@ -97,12 +97,19 @@ func (c *testControllerHandle) HiParamEmptyInputBy() string {
return "empty in but served with ctx.Params.Get('ps')=" + c.Ctx.Params().Get("ps")
}
type testSmallController struct{}
// test ctx + id in the same time.
func (c *testSmallController) GetHiParamEmptyInputWithCtxBy(ctx context.Context, id string) string {
return "empty in but served with ctx.Params.Get('param2')= " + ctx.Params().Get("param2") + " == id == " + id
}
func TestControllerHandle(t *testing.T) {
app := iris.New()
m := New(app)
m.Register(&TestServiceImpl{prefix: "service:"})
m.Handle(new(testControllerHandle))
m.Handle(new(testSmallController))
e := httptest.New(t, app)
@ -130,4 +137,6 @@ func TestControllerHandle(t *testing.T) {
Body().Equal("value")
e.GET("/hiparamempyinput/value").Expect().Status(httptest.StatusOK).
Body().Equal("empty in but served with ctx.Params.Get('ps')=value")
e.GET("/hi/param/empty/input/with/ctx/value").Expect().Status(httptest.StatusOK).
Body().Equal("empty in but served with ctx.Params.Get('param2')= value == id == value")
}

View File

@ -35,16 +35,21 @@ func getPathParamsForInput(params []macro.TemplateParam, funcIn ...reflect.Type)
// }
// }
for i, param := range params {
if len(funcIn) <= i {
return
}
funcDep, ok := context.ParamResolverByTypeAndIndex(funcIn[i], param.Index)
if !ok {
continue
}
consumed := make(map[int]struct{})
for _, in := range funcIn {
for j, param := range params {
if _, ok := consumed[j]; ok {
continue
}
funcDep, ok := context.ParamResolverByTypeAndIndex(in, param.Index)
if !ok {
continue
}
values = append(values, funcDep)
values = append(values, funcDep)
consumed[j] = struct{}{}
break
}
}
return