From ee9223b1b9b5dad70080fe437517ab288dad127b Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 8 Jul 2013 17:35:09 +0800 Subject: [PATCH] fix #18 func (this *MainController) Get() { this.GoToFunc("Test") } func (this *MainController) Test() { this.Ctx.WriteString("testtest") } --- controller.go | 8 ++++++++ router.go | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/controller.go b/controller.go index c37109b8..bca9f978 100644 --- a/controller.go +++ b/controller.go @@ -33,6 +33,7 @@ type Controller struct { Layout string TplExt string _xsrf_token string + gotofunc string CruSession session.SessionStore } @@ -376,3 +377,10 @@ func (c *Controller) XsrfFormHtml() string { return "" } + +func (c *Controller) GoToFunc(funcname string) { + if funcname[0] < 65 || funcname[0] > 90 { + panic("GoToFunc should exported function") + } + c.gotofunc = funcname +} diff --git a/router.go b/router.go index cbdbb7d8..37f45899 100644 --- a/router.go +++ b/router.go @@ -404,6 +404,15 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) method = vc.MethodByName("Options") method.Call(in) } + gotofunc := vc.Elem().FieldByName("gotofunc").String() + if gotofunc != "" { + method = vc.MethodByName(gotofunc) + if method.IsValid() { + method.Call(in) + } else { + panic("gotofunc is exists:" + gotofunc) + } + } if !w.started { if AutoRender { method = vc.MethodByName("Render")