mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
Former-commit-id: d95be1456a78fbafd7ec5fec22f2066454eb76c6
This commit is contained in:
parent
444a4a0363
commit
df3a68255c
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
23
mvc/param.go
23
mvc/param.go
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user