1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-10 05:25:58 +00:00

version 12.1.5

Former-commit-id: cda69f08955cb0d594e98bf26197ee573cbba4b2
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-02-02 16:29:06 +02:00
parent e04ea83c04
commit 3093d65363
76 changed files with 9647 additions and 366 deletions

View File

@@ -273,11 +273,7 @@ func (c *ControllerActivator) activate() {
}
func (c *ControllerActivator) addErr(err error) bool {
if c.router.GetReporter().Err(err) != nil {
return true
}
return false
return c.router.GetReporter().Err(err) != nil
}
// register all available, exported methods to handlers if possible.
@@ -492,7 +488,7 @@ func (c *ControllerActivator) handlerOf(m reflect.Method, funcDependencies []ref
ctxValue = reflect.ValueOf(ctx)
}
in := make([]reflect.Value, n, n)
in := make([]reflect.Value, n)
in[0] = ctrl
funcInjector.Inject(&in, ctxValue)

View File

@@ -87,15 +87,6 @@ func (l *methodLexer) peekNext() (w string) {
return l.peek(l.cur + 1)
}
func (l *methodLexer) peekPrev() (w string) {
if l.cur > 0 {
cur := l.cur - 1
w = l.words[cur]
}
return w
}
func genParamKey(argIdx int) string {
return "param" + strconv.Itoa(argIdx) // param0, param1, param2...
}

View File

@@ -537,3 +537,51 @@ func TestControllerNotCreateNewDueManuallySettingAllFields(t *testing.T) {
e.GET("/").Expect().Status(iris.StatusOK).
Body().Equal("my title")
}
type testControllerRequestScopedDependencies struct {
MyContext *testMyContext
CustomStruct *testCustomStruct
}
func (c *testControllerRequestScopedDependencies) Get() *testCustomStruct {
return c.CustomStruct
}
func (c *testControllerRequestScopedDependencies) GetCustomContext() string {
return c.MyContext.OtherField
}
func newRequestDep1(ctx context.Context) *testCustomStruct {
return &testCustomStruct{
Name: ctx.URLParam("name"),
Age: ctx.URLParamIntDefault("age", 0),
}
}
type testMyContext struct {
Context context.Context
OtherField string
}
func newRequestDep2(ctx context.Context) *testMyContext {
return &testMyContext{
Context: ctx,
OtherField: "test",
}
}
func TestControllerRequestScopedDependencies(t *testing.T) {
app := iris.New()
m := New(app)
m.Register(newRequestDep1)
m.Register(newRequestDep2)
m.Handle(new(testControllerRequestScopedDependencies))
e := httptest.New(t, app)
e.GET("/").WithQuery("name", "kataras").WithQuery("age", 27).
Expect().Status(httptest.StatusOK).JSON().Equal(&testCustomStruct{
Name: "kataras",
Age: 27,
})
e.GET("/custom/context").Expect().Status(httptest.StatusOK).Body().Equal("test")
}

View File

@@ -39,7 +39,7 @@ func hasErrorOutArgs(fn reflect.Method) bool {
func getInputArgsFromFunc(funcTyp reflect.Type) []reflect.Type {
n := funcTyp.NumIn()
funcIn := make([]reflect.Type, n, n)
funcIn := make([]reflect.Type, n)
for i := 0; i < n; i++ {
funcIn[i] = funcTyp.In(i)
}