-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
MVC how to use multiple Handler? #754
Comments
Yes, It is possible with Iris. You need to Create and Use "Middleware" for that. |
Is there no direct or simpler method? Because I think the middelware is inappropriate for my purposes, but it wouldn't be nice to have to go back to the non-MVC-style for some paths. |
You can override BeginRequest for your mvc controller and add some handlers to the context. |
@praeto are you abel to show me a example, because i get with my try only a panic |
// BeginRequest saves login state to the context, the user id.
func (c *MyController) BeginRequest(ctx iris.Context) {
c.Ctx.AddHandler(func(ctx2 iris.Context) { // LINE 21
userID, err := ctx2.Params().GetInt64("user")
if err != nil {
logR.Println(err.Error())
}
if userID > 0 {
logR.Println(userID, "Erfolgreich")
}
})
}
|
@NextGringo, you should first call default
|
@NextGringo, sorry, I forgot to mention that after adding handlers you should call them
|
ok, now it works. |
|
Hi, I can't finde any info about how to use multiple handler for a function in a controller.
I would like to use for some routes(funcs) a pre handler func, that checks if a user is loggedIn and load then the needed Informations, else it should Skip the next handler and use the next after it.
Is there a possibility for that? Or need I code that all now in one handle?
The text was updated successfully, but these errors were encountered: