Issues with variadic controller functions #60

Closed
eaigner opened this Issue Jan 12, 2013 · 6 comments

Comments

Projects
None yet
2 participants

eaigner commented Jan 12, 2013

I created a custom controller and added following variadic method to it

func (c *Controller) RenderJsonError(code int, messages ...string) rev.Result

When the route is loaded where this method is used, revel complains with the following message

In web/app/tmp/main.go (around line 33)
28  []*rev.MethodType{
29    &rev.MethodType{
30      Name: "RenderJsonError",
31      Args: []*rev.MethodArg{ 
32          &rev.MethodArg{Name: "code", Type: reflect.TypeOf((*int)(nil)) },
33          &rev.MethodArg{Name: "messages", Type: reflect.TypeOf((*)(nil)) },
34      },
35      RenderArgNames: map[int][]string{ 
36      },
37  },

If I put a []string there instead of ...string no error is reported.

Contributor

robfig commented Jan 13, 2013

Thank you for this report. It highlights two issues:

  • Revel does not properly discover the variadic type for the argument.
  • This func is probably not an Action that should be invokable, but there is no way to tell Revel that (without making it unexported). (Play uses the @Util annotation to indicate functions that are utility rather than actions)

I will resolve the first issue shortly. I'm not sure I have any great ideas for resolving the second, other than unpleasant ones like requiring the method name to start with "Util" -- any ideas?

@robfig robfig closed this in 8e08d09 Jan 13, 2013

eaigner commented Jan 13, 2013

Well there is always the option to avoid it all-together by making it a function rather than a controller method

func DoThis(c *rev.Controller)

eaigner commented Jan 13, 2013

Would it be possible to derive what is an exposed controller method and what isn't from the routes file?

Contributor

robfig commented Jan 13, 2013

There is generally a catch-all route that makes all actions accessible {controller}.{action}

eaigner commented Jan 13, 2013

Right.

eaigner commented Jan 13, 2013

What about this idea?

type Controller struct {
  *rev.Controller
  IgnoreMethodName rev.Annotation
}

Then the method MethodName would be ignored. This way you could "fake" annotations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment