Iris: [BUG] MVC BeforeActivation does not register route for all Methods

Created on 12 Jun 2020  ·  7Comments  ·  Source: kataras/iris

Describe the bug
It seems that the current master branch has a problem with the MVC.

If I use the following controller:


// Authenticated is a custom type used as "annotation" for resources that requires authentication,
// its value should be the logged user ID.
type Authenticated uint64

// UserMeController provides the logged user's available actions.
type UserMeController struct {
    CurrentUserID Authenticated
}

// BeforeActivation desc
func (c *UserMeController) BeforeActivation(b mvc.BeforeActivation) {
    b.Handle("POST", "/me/tos-read", "MeTOSRead")
    b.Handle("GET", "/me/tos-read", "MeTOSRead")
}

// MeTOSRead returns a message for the sake of the example.
// a route via `BeforeActivation#Handle` (look above)
// POST: /user/me/tos-read (see abdove BeforeActivation)
func (c *UserMeController) MeTOSRead() string {
    return "This will be executed only when the user is logged in"
}

this route is not found for both methods.

[DBUG] 2020/06/12 20:06 API: 8 registered routes (4 GET and 4 POST)
GET: /user/me/stats controller (./main.go:30)
     • controller.UserMeController.GetMeStats (./controller/UserMeController.go:63)
GET: /user/me controller (./main.go:30)
     • controller.UserMeController.GetMe (./controller/UserMeController.go:31)
GET: /user controller (./main.go:31)
     • controller.UserPublicController.Get (./controller/UserPublicController.go:9)
GET: /game controller (./main.go:43)
     • controller.GameDataController.Get (./controller/GameDataController.go:16)

POST: /user/me/tos-read controller (./controller/UserMeController.go:19)
      • controller.UserMeController.MeTOSRead (./controller/UserMeController.go:76)
POST: /user/me controller (./main.go:30)
      • controller.UserMeController.PostMe (./controller/UserMeController.go:69)
POST: /user/login controller (./main.go:31)
      • controller.UserPublicController.PostLogin (./controller/UserPublicController.go:15)
POST: /user/register controller (./main.go:31)
      • controller.UserPublicController.PostRegister (./controller/UserPublicController.go:21)

POST -> /user/me/tos-read -> POST /user/me/tos-read
GET -> /user/me/stats -> GET /user/me/stats
GET -> /user/me -> GET /user/me
POST -> /user/me -> POST /user/me
GET -> /user -> GET /user
POST -> /user/login -> POST /user/login
POST -> /user/register -> POST /user/register
GET -> /game -> GET /game
Now listening on: http://localhost:8080
Application started. Press CTRL+C to shut down.

To Reproduce
Steps to reproduce the behavior:

  1. [...]

Expected behavior
Both Methods should be registed to the same Controller Method/Func.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. ubuntu, windows]

Additional context
Add any other context about the problem here.

resolved bug

All 7 comments

Hello @Dexus,

Thanks for the bug report, it's fixed. Also I did a small change, if the Handle/HandleMany is called on activation, then the controller will not try to register it at all (even if it's method's prefix is a http method literal that is not yet registered by BeforeActivation), and secondly, on Handle the routes are appending to the controller's method name, and on HandleMany it will override any previously registered by before activation.

Both Handle and HandleMany can accept more than one method and path in the same line, separated by a space, i.e: b.HandleMany("GET POST", "/me/tos-read", "MeTOSRead")

Thanks, by the looks of it, it now works like it used to in v6.

You're welcome! (in v6 we didn't had mvc, you mean v11.x.x-v12.1.8)

I'm with Iris since v4 or was it already v5... can't remember all the changes and features anymore.

I know @Dexus, and I really appreciate it, you even use the master branch and sending bug reports for it, like a beta user(❤️). That's why I am offering you to be the first Certified Iris Developer, the certificate will look like this:

Iris Certification (2)

I feel you, we make a lot of progress and introducing new features on each release, things that are unique and things that coming from other languages. That makes Iris the most complete and with advanced features across its alternatives for Go(lang).

I'm happy to do it.
It's worth it to be there early, even if there are still bugs sometimes.

With Iris goes with the times and has not stood still compared to others. Also that you continued after V6/7? I can't remember exactly, but I'm very happy about it. Also with all the history around.

I am honored to receive the offer from you to be the first Certified Iris Developer. Where to take the exam ❤️

Hello @Dexus,

Thanks for your nice words! I sent you an email (the public one you have on github).

If you require any further information, or you have any recommendations about the exam, feel free to contact me.

Was this page helpful?
0 / 5 - 0 ratings