MCPcopy
hub / github.com/revel/revel / SetTypeAction

Method SetTypeAction

controller.go:389–431  ·  view source on GitHub ↗

SetAction sets the assigns the Controller type, sets the action and initializes the controller.

(controllerName, methodName string, typeOfController *ControllerType)

Source from the content-addressed store, hash-verified

387
388// SetAction sets the assigns the Controller type, sets the action and initializes the controller.
389func (c *Controller) SetTypeAction(controllerName, methodName string, typeOfController *ControllerType) error {
390 // Look up the controller and method types.
391 if typeOfController == nil {
392 if c.Type = ControllerTypeByName(controllerName, anyModule); c.Type == nil {
393 return errors.New("revel/controller: failed to find controller " + controllerName)
394 }
395 } else {
396 c.Type = typeOfController
397 }
398
399 // Note method name is case insensitive search
400 if c.MethodType = c.Type.Method(methodName); c.MethodType == nil {
401 return errors.New("revel/controller: failed to find action " + controllerName + "." + methodName)
402 }
403
404 c.Name, c.MethodName = c.Type.Type.Name(), c.MethodType.Name
405 c.Action = c.Name + "." + c.MethodName
406
407 // Update Logger with controller and namespace
408 if c.Log != nil {
409 c.Log = c.Log.New("action", c.Action, "namespace", c.Type.Namespace)
410 }
411
412 if RevelConfig.Controller.Reuse {
413 if _, ok := RevelConfig.Controller.CachedMap[c.Name]; !ok {
414 // Create a new stack for this controller
415 localType := c.Type.Type
416 RevelConfig.Controller.CachedMap[c.Name] = utils.NewStackLock(
417 RevelConfig.Controller.CachedStackSize,
418 RevelConfig.Controller.CachedStackMaxSize,
419 func() interface{} {
420 return reflect.New(localType).Interface()
421 })
422 }
423 // Instantiate the controller.
424 c.AppController = RevelConfig.Controller.CachedMap[c.Name].Pop()
425 } else {
426 c.AppController = reflect.New(c.Type.Type).Interface()
427 }
428 c.setAppControllerFields()
429
430 return nil
431}
432
433func ControllerTypeByName(controllerName string, moduleSource *Module) (c *ControllerType) {
434 var found bool

Callers 3

validateRouteFunction · 0.95
SetActionMethod · 0.95
RouterFilterFunction · 0.80

Calls 7

NewStackLockFunction · 0.92
ControllerTypeByNameFunction · 0.85
MethodMethod · 0.80
PopMethod · 0.80
NewMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected