mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 10:27:06 +00:00
Former-commit-id: 1e2c7185fc3c536ceb8b269c75b9a2c19323960b
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<!-- # Iris Web Framework <a href="README_ZH.md"> <img width="20px" src="https://iris-go.com/images/flag-china.svg?v=10" /></a> <a href="README_RU.md"><img width="20px" src="https://iris-go.com/images/flag-russia.svg?v=10" /></a> <a href="README_ID.md"> <img width="20px" src="https://iris-go.com/images/flag-indonesia.svg?v=10" /></a> <a href="README_GR.md"><img width="20px" src="https://iris-go.com/images/flag-greece.svg?v=10" /></a> <a href="README_PT_BR.md"><img width="20px" src="https://iris-go.com/images/flag-pt-br.svg?v=10" /></a> <a href="README_JPN.md"><img width="20px" src="https://iris-go.com/images/flag-japan.svg?v=10" /></a> -->
|
||||
|
||||
# Iris <a href="README.md"> <img width="20px" src="https://iris-go.com/images/flag-unitedkingdom.svg?v=10" /></a> <a href="README_ZH.md"><img width="20px" src="https://iris-go.com/images/flag-china.svg?v=10" /></a> <a href="README_GR.md"><img width="20px" src="https://iris-go.com/images/flag-greece.svg?v=10" /></a> <a href="README_KO.md"><img width="20px" src="https://upload.wikimedia.org/wikipedia/commons/0/09/Flag_of_South_Korea.svg" />
|
||||
# Iris <a href="README.md"> <img width="20px" src="https://iris-go.com/images/flag-unitedkingdom.svg?v=10" /></a> <a href="README_ZH.md"><img width="20px" src="https://iris-go.com/images/flag-china.svg?v=10" /></a> <a href="README_GR.md"><img width="20px" src="https://iris-go.com/images/flag-greece.svg?v=10" /></a> <a href="README_KO.md"><img width="20px" src="https://iris-go.com/images/flag-south-korea.svg" />
|
||||
|
||||
[](https://travis-ci.org/kataras/iris) [](https://goreportcard.com/report/github.com/kataras/iris)<!--[](https://godoc.org/github.com/kataras/iris)--> [](https://github.com/kataras/iris/tree/master/_examples) [](https://gitter.im/iris_go/community) [](https://github.com/kataras/iris/releases)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Iris <a href="README.md"> <img width="20px" src="https://iris-go.com/images/flag-unitedkingdom.svg?v=10" /></a> <a href="README_ZH.md"><img width="20px" src="https://iris-go.com/images/flag-china.svg?v=10" /></a> <a href="README_ES.md"><img width="20px" src="https://iris-go.com/images/flag-spain.png" /></a> <a href="README_KO.md"><img width="20px" src="https://upload.wikimedia.org/wikipedia/commons/0/09/Flag_of_South_Korea.svg" />
|
||||
# Iris <a href="README.md"> <img width="20px" src="https://iris-go.com/images/flag-unitedkingdom.svg?v=10" /></a> <a href="README_ZH.md"><img width="20px" src="https://iris-go.com/images/flag-china.svg?v=10" /></a> <a href="README_ES.md"><img width="20px" src="https://iris-go.com/images/flag-spain.png" /></a> <a href="README_KO.md"><img width="20px" src="https://iris-go.com/images/flag-south-korea.svg" />
|
||||
|
||||
[](https://travis-ci.org/kataras/iris) [](https://goreportcard.com/report/github.com/kataras/iris)<!--[](https://godoc.org/github.com/kataras/iris)--> [](https://github.com/kataras/iris/tree/master/_examples) [](https://gitter.im/iris_go/community) [](https://github.com/kataras/iris/releases)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<!-- # Iris Web Framework <a href="README_ZH.md"> <img width="20px" src="https://iris-go.com/images/flag-china.svg?v=10" /></a> <a href="README_RU.md"><img width="20px" src="https://iris-go.com/images/flag-russia.svg?v=10" /></a> <a href="README_ID.md"> <img width="20px" src="https://iris-go.com/images/flag-indonesia.svg?v=10" /></a> <a href="README_GR.md"><img width="20px" src="https://iris-go.com/images/flag-greece.svg?v=10" /></a> <a href="README_PT_BR.md"><img width="20px" src="https://iris-go.com/images/flag-pt-br.svg?v=10" /></a> <a href="README_JPN.md"><img width="20px" src="https://iris-go.com/images/flag-japan.svg?v=10" /></a> -->
|
||||
|
||||
# Iris <a href="README.md"> <img width="20px" src="https://iris-go.com/images/flag-unitedkingdom.svg?v=10" /></a> <a href="README_GR.md"><img width="20px" src="https://iris-go.com/images/flag-greece.svg?v=10" /></a> <a href="README_ES.md"><img width="20px" src="https://iris-go.com/images/flag-spain.png" /></a> <a href="README_KO.md"><img width="20px" src="https://upload.wikimedia.org/wikipedia/commons/0/09/Flag_of_South_Korea.svg" />
|
||||
# Iris <a href="README.md"> <img width="20px" src="https://iris-go.com/images/flag-unitedkingdom.svg?v=10" /></a> <a href="README_GR.md"><img width="20px" src="https://iris-go.com/images/flag-greece.svg?v=10" /></a> <a href="README_ES.md"><img width="20px" src="https://iris-go.com/images/flag-spain.png" /></a> <a href="README_KO.md"><img width="20px" src=""https://iris-go.com/images/flag-south-korea.svg" />
|
||||
|
||||
[](https://travis-ci.org/kataras/iris) [](https://goreportcard.com/report/github.com/kataras/iris)<!--[](https://godoc.org/github.com/kataras/iris)--> [](https://github.com/kataras/iris/tree/master/_examples) [](https://gitter.im/iris_go/community) [](https://github.com/kataras/iris/releases)
|
||||
|
||||
|
||||
@@ -70,6 +70,9 @@ type ControllerActivator struct {
|
||||
// to register any custom controller's methods as handlers.
|
||||
router router.Party
|
||||
|
||||
macros macro.Macros
|
||||
tmplParamStartIndex int
|
||||
|
||||
// initRef BaseController // the BaseController as it's passed from the end-dev.
|
||||
Value reflect.Value // the BaseController's Value.
|
||||
Type reflect.Type // raw type of the BaseController (initRef).
|
||||
@@ -116,6 +119,7 @@ func newControllerActivator(router router.Party, controller interface{}, depende
|
||||
// give access to the Router to the end-devs if they need it for some reason,
|
||||
// i.e register done handlers.
|
||||
router: router,
|
||||
macros: *router.Macros(),
|
||||
Value: reflect.ValueOf(controller),
|
||||
Type: typ,
|
||||
// the full name of the controller: its type including the package path.
|
||||
@@ -133,6 +137,8 @@ func newControllerActivator(router router.Party, controller interface{}, depende
|
||||
errorHandler: errorHandler,
|
||||
}
|
||||
|
||||
fpath, _ := macro.Parse(c.router.GetRelPath(), c.macros)
|
||||
c.tmplParamStartIndex = len(fpath.Params)
|
||||
return c
|
||||
}
|
||||
|
||||
@@ -339,7 +345,7 @@ func (c *ControllerActivator) handleMany(method, path, funcName string, override
|
||||
}
|
||||
|
||||
// parse a route template which contains the parameters organised.
|
||||
tmpl, err := macro.Parse(path, *c.router.Macros())
|
||||
tmpl, err := macro.Parse(path, c.macros)
|
||||
if err != nil {
|
||||
c.addErr(fmt.Errorf("MVC: fail to parse the path for '%s.%s': %v", c.fullName, funcName, err))
|
||||
return nil
|
||||
@@ -350,7 +356,7 @@ func (c *ControllerActivator) handleMany(method, path, funcName string, override
|
||||
// get the path parameters bindings from the template,
|
||||
// use the function's input except the receiver which is the
|
||||
// end-dev's controller pointer.
|
||||
pathParams := getPathParamsForInput(tmpl.Params, funcIn[1:]...)
|
||||
pathParams := getPathParamsForInput(c.tmplParamStartIndex, tmpl.Params, funcIn[1:]...)
|
||||
// get the function's input arguments' bindings.
|
||||
funcDependencies := c.dependencies.Clone()
|
||||
funcDependencies.AddValues(pathParams...)
|
||||
|
||||
@@ -166,3 +166,20 @@ func TestControllerHandle(t *testing.T) {
|
||||
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")
|
||||
}
|
||||
|
||||
type testControllerHandleWithDynamicPathPrefix struct {
|
||||
Ctx iris.Context
|
||||
}
|
||||
|
||||
func (c *testControllerHandleWithDynamicPathPrefix) GetBy(id string) string {
|
||||
params := c.Ctx.Params()
|
||||
return params.Get("model") + params.Get("action") + id
|
||||
}
|
||||
|
||||
func TestControllerHandleWithDynamicPathPrefix(t *testing.T) {
|
||||
app := iris.New()
|
||||
New(app.Party("/api/data/{model:string}/{action:string}")).Handle(new(testControllerHandleWithDynamicPathPrefix))
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/api/data/mymodel/myaction/myid").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("mymodelmyactionmyid")
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/kataras/iris/macro"
|
||||
)
|
||||
|
||||
func getPathParamsForInput(params []macro.TemplateParam, funcIn ...reflect.Type) (values []reflect.Value) {
|
||||
func getPathParamsForInput(startParamIndex int, params []macro.TemplateParam, funcIn ...reflect.Type) (values []reflect.Value) {
|
||||
if len(funcIn) == 0 || len(params) == 0 {
|
||||
return
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func getPathParamsForInput(params []macro.TemplateParam, funcIn ...reflect.Type)
|
||||
continue
|
||||
}
|
||||
|
||||
funcDep, ok := context.ParamResolverByTypeAndIndex(in, param.Index)
|
||||
funcDep, ok := context.ParamResolverByTypeAndIndex(in, startParamIndex+param.Index)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user