mirror of
https://github.com/kataras/iris.git
synced 2025-02-09 02:34:55 +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"
|
"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()
|
var def = New()
|
||||||
|
|
||||||
// Hero contains the Dependencies which will be binded
|
// 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")
|
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) {
|
func TestControllerHandle(t *testing.T) {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
|
|
||||||
m := New(app)
|
m := New(app)
|
||||||
m.Register(&TestServiceImpl{prefix: "service:"})
|
m.Register(&TestServiceImpl{prefix: "service:"})
|
||||||
m.Handle(new(testControllerHandle))
|
m.Handle(new(testControllerHandle))
|
||||||
|
m.Handle(new(testSmallController))
|
||||||
|
|
||||||
e := httptest.New(t, app)
|
e := httptest.New(t, app)
|
||||||
|
|
||||||
|
@ -130,4 +137,6 @@ func TestControllerHandle(t *testing.T) {
|
||||||
Body().Equal("value")
|
Body().Equal("value")
|
||||||
e.GET("/hiparamempyinput/value").Expect().Status(httptest.StatusOK).
|
e.GET("/hiparamempyinput/value").Expect().Status(httptest.StatusOK).
|
||||||
Body().Equal("empty in but served with ctx.Params.Get('ps')=value")
|
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 {
|
consumed := make(map[int]struct{})
|
||||||
if len(funcIn) <= i {
|
for _, in := range funcIn {
|
||||||
return
|
for j, param := range params {
|
||||||
}
|
if _, ok := consumed[j]; ok {
|
||||||
funcDep, ok := context.ParamResolverByTypeAndIndex(funcIn[i], param.Index)
|
continue
|
||||||
if !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
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user