1 // Copyright (c) 2012-2016 The Revel Framework Authors, All rights reserved.
2 // Revel Framework source code and usage is governed by a MIT style
3 // license that can be found in the LICENSE file.
13 controllerPtrType = reflect.TypeOf(&Controller{})
14 websocketType = reflect.TypeOf((*ServerWebSocket)(nil)).Elem()
17 func ActionInvoker(c *Controller, _ []Filter) {
18 // Instantiate the method.
19 methodValue := reflect.ValueOf(c.AppController).MethodByName(c.MethodType.Name)
21 // Collect the values for the method's arguments.
22 var methodArgs []reflect.Value
23 for _, arg := range c.MethodType.Args {
24 // If they accept a websocket connection, treat that arg specially.
25 var boundArg reflect.Value
26 if arg.Type.Implements(websocketType) {
27 boundArg = reflect.ValueOf(c.Request.WebSocket)
29 boundArg = Bind(c.Params, arg.Name, arg.Type)
30 // #756 - If the argument is a closer, defer a Close call,
31 // so we don't risk on leaks.
32 if closer, ok := boundArg.Interface().(io.Closer); ok {
38 methodArgs = append(methodArgs, boundArg)
41 var resultValue reflect.Value
42 if methodValue.Type().IsVariadic() {
43 resultValue = methodValue.CallSlice(methodArgs)[0]
45 resultValue = methodValue.Call(methodArgs)[0]
47 if resultValue.Kind() == reflect.Interface && !resultValue.IsNil() {
48 c.Result = resultValue.Interface().(Result)