From a62ed10ab3258edf7d50c11e6e24fd8576a20351 Mon Sep 17 00:00:00 2001 From: astaxie Date: Sat, 28 Sep 2013 23:30:36 +0800 Subject: [PATCH] add supoort AppController http://play.golang.org/p/MZptHZeYUx --- controller.go | 24 +++++++++++++----------- router.go | 1 + 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/controller.go b/controller.go index f966f934..87f331cf 100644 --- a/controller.go +++ b/controller.go @@ -22,16 +22,17 @@ import ( ) type Controller struct { - Ctx *context.Context - Data map[interface{}]interface{} - ChildName string - TplNames string - Layout string - TplExt string - _xsrf_token string - gotofunc string - CruSession session.SessionStore - XSRFExpire int + Ctx *context.Context + Data map[interface{}]interface{} + ChildName string + TplNames string + Layout string + TplExt string + _xsrf_token string + gotofunc string + CruSession session.SessionStore + XSRFExpire int + AppController interface{} } type ControllerInterface interface { @@ -48,13 +49,14 @@ type ControllerInterface interface { Render() error } -func (c *Controller) Init(ctx *context.Context, childName string) { +func (c *Controller) Init(ctx *context.Context, childName string, app interface{}) { c.Data = make(map[interface{}]interface{}) c.Layout = "" c.TplNames = "" c.ChildName = childName c.Ctx = ctx c.TplExt = "tpl" + c.AppController = app } func (c *Controller) Prepare() { diff --git a/router.go b/router.go index db12bb1f..12474f6c 100644 --- a/router.go +++ b/router.go @@ -448,6 +448,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) in := make([]reflect.Value, 2) in[0] = reflect.ValueOf(context) in[1] = reflect.ValueOf(runrouter.controllerType.Name()) + in[2] = reflect.ValueOf(vc.Interface()) method.Call(in) //if XSRF is Enable then check cookie where there has any cookie in the request's cookie _csrf