1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-22 22:20:50 +00:00
func (this *MainController) Get() {
this.GoToFunc("Test")
}

func (this *MainController) Test() {
this.Ctx.WriteString("testtest")
}
This commit is contained in:
astaxie 2013-07-08 17:35:09 +08:00
parent d2a16ff8f6
commit ee9223b1b9
2 changed files with 17 additions and 0 deletions

View File

@ -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 "<input type=\"hidden\" name=\"_xsrf\" value=\"" +
c._xsrf_token + "\"/>"
}
func (c *Controller) GoToFunc(funcname string) {
if funcname[0] < 65 || funcname[0] > 90 {
panic("GoToFunc should exported function")
}
c.gotofunc = funcname
}

View File

@ -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")