Commit ee9223b1 authored by astaxie's avatar astaxie

fix #18

func (this *MainController) Get() {
this.GoToFunc("Test")
}

func (this *MainController) Test() {
this.Ctx.WriteString("testtest")
}
parent d2a16ff8
...@@ -33,6 +33,7 @@ type Controller struct { ...@@ -33,6 +33,7 @@ type Controller struct {
Layout string Layout string
TplExt string TplExt string
_xsrf_token string _xsrf_token string
gotofunc string
CruSession session.SessionStore CruSession session.SessionStore
} }
...@@ -376,3 +377,10 @@ func (c *Controller) XsrfFormHtml() string { ...@@ -376,3 +377,10 @@ func (c *Controller) XsrfFormHtml() string {
return "<input type=\"hidden\" name=\"_xsrf\" value=\"" + return "<input type=\"hidden\" name=\"_xsrf\" value=\"" +
c._xsrf_token + "\"/>" c._xsrf_token + "\"/>"
} }
func (c *Controller) GoToFunc(funcname string) {
if funcname[0] < 65 || funcname[0] > 90 {
panic("GoToFunc should exported function")
}
c.gotofunc = funcname
}
...@@ -404,6 +404,15 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -404,6 +404,15 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
method = vc.MethodByName("Options") method = vc.MethodByName("Options")
method.Call(in) 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 !w.started {
if AutoRender { if AutoRender {
method = vc.MethodByName("Render") method = vc.MethodByName("Render")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment