mirror of
https://github.com/kataras/iris.git
synced 2025-03-14 02:46:28 +01:00
MVC: Add support for ByBy
as requested https://github.com/kataras/iris/issues/751
Former-commit-id: 78c2453c56000c2268e11e68d7b530251e2beedd
This commit is contained in:
parent
ff8f96d56d
commit
ab8235d398
|
@ -70,14 +70,23 @@ func (p *funcParser) parse() (*ast, error) {
|
|||
typ := p.info.Type
|
||||
funcArgPos++ // starting with 1 because in typ.NumIn() the first is the struct receiver.
|
||||
|
||||
if p.lexer.peekPrev() == tokenBy || typ.NumIn() == 1 { // ByBy, then act this second By like a path
|
||||
a.relPath += "/" + strings.ToLower(w)
|
||||
continue
|
||||
}
|
||||
// No need for these:
|
||||
// ByBy will act like /{param:type}/{param:type} as users expected
|
||||
// if func input arguments are there, else act By like normal path /by.
|
||||
//
|
||||
// if p.lexer.peekPrev() == tokenBy || typ.NumIn() == 1 { // ByBy, then act this second By like a path
|
||||
// a.relPath += "/" + strings.ToLower(w)
|
||||
// continue
|
||||
// }
|
||||
|
||||
if typ.NumIn() <= funcArgPos {
|
||||
return nil, errors.New("keyword 'By' found but length of input receivers are not match for " +
|
||||
p.info.Name)
|
||||
// old:
|
||||
// return nil, errors.New("keyword 'By' found but length of input receivers are not match for " +
|
||||
// p.info.Name)
|
||||
|
||||
// By found but input arguments are not there, so act like /by path without restricts.
|
||||
a.relPath += "/" + strings.ToLower(w)
|
||||
continue
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
|
@ -456,6 +456,7 @@ func (c *testControllerRelPathFromFunc) GetAdminLogin() {}
|
|||
|
||||
func (c *testControllerRelPathFromFunc) PutSomethingIntoThis() {}
|
||||
func (c *testControllerRelPathFromFunc) GetSomethingBy(bool) {}
|
||||
func (c *testControllerRelPathFromFunc) GetSomethingByBy(string, int) {}
|
||||
func (c *testControllerRelPathFromFunc) GetSomethingByElseThisBy(bool, int) {} // two input arguments
|
||||
|
||||
func TestControllerRelPathFromFunc(t *testing.T) {
|
||||
|
@ -474,6 +475,8 @@ func TestControllerRelPathFromFunc(t *testing.T) {
|
|||
Body().Equal("GET:/something/false")
|
||||
e.GET("/something/truee").Expect().Status(httptest.StatusNotFound)
|
||||
e.GET("/something/falsee").Expect().Status(httptest.StatusNotFound)
|
||||
e.GET("/something/kataras/42").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("GET:/something/kataras/42")
|
||||
e.GET("/something/true/else/this/42").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("GET:/something/true/else/this/42")
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user