New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use HandleMany in mvc #1292
Comments
How should I achieve this? |
You can create two methods that calls your |
func (*C) BeforeActivation(b mvc.BeforeActivation) {
b.Handle("GET", "/test1", "Get")
b.Handle("GET", "/test2", "Get")
}
func (*C) Get(ctx iris.Context) {
ctx.WriteString("context")
} I use it like this, second route cannot match the handle. @kataras |
Registering the same controller method twice is not allowed by purpose, it's not a bug: Lines 78 to 81 in 6c054a9
Lines 315 to 318 in 6c054a9
Why? because you can get a route based on the controller method through: Instead, this I purposed to you above was something like this: func (*C) GetTest1(ctx iris.Context) {
ctx.WriteString("context")
}
func (*C) GetTest2(ctx iris.Context) {
c.GetTest1(ctx)
} If we allow more than one routes to registered to one controller method then the API of |
It's done on v11.2 without breaking changes with commits: Example: iris/_examples/mvc/basic/main.go Lines 76 to 78 in a71ad42
This is also possible: type Package struct {
Ctx iris.Context
}
func (*Package) BeforeActivation(b mvc.BeforeActivation) {
b.HandleMany("GET", " /{scope:string}/{package:string} /{package:string}", "MyHandle")
}
func (*Package) MyHandle(pkg, scope string) string {
return pkg+scope
}
Thanks @gongchao. |
…ng} /custom3/{ps:string}, CtrlMethodName) relative to: #1292
…ested at: kataras#1292 Former-commit-id: c021f49522a214ddc3978a1c8f5e8d32f029eb2d
…ng} /custom3/{ps:string}, CtrlMethodName) relative to: kataras#1292 Former-commit-id: de08c5eeab7a1c2729fbff7260de00cc2516f78c
The text was updated successfully, but these errors were encountered: