fix #18
func (this *MainController) Get() {
this.GoToFunc("Test")
}
func (this *MainController) Test() {
this.Ctx.WriteString("testtest")
}
Showing
2 changed files
with
17 additions
and
0 deletions
| ... | @@ -33,6 +33,7 @@ type Controller struct { | ... | @@ -33,6 +33,7 @@ type Controller struct { |
| 33 | Layout string | 33 | Layout string |
| 34 | TplExt string | 34 | TplExt string |
| 35 | _xsrf_token string | 35 | _xsrf_token string |
| 36 | gotofunc string | ||
| 36 | CruSession session.SessionStore | 37 | CruSession session.SessionStore |
| 37 | } | 38 | } |
| 38 | 39 | ||
| ... | @@ -376,3 +377,10 @@ func (c *Controller) XsrfFormHtml() string { | ... | @@ -376,3 +377,10 @@ func (c *Controller) XsrfFormHtml() string { |
| 376 | return "<input type=\"hidden\" name=\"_xsrf\" value=\"" + | 377 | return "<input type=\"hidden\" name=\"_xsrf\" value=\"" + |
| 377 | c._xsrf_token + "\"/>" | 378 | c._xsrf_token + "\"/>" |
| 378 | } | 379 | } |
| 380 | |||
| 381 | func (c *Controller) GoToFunc(funcname string) { | ||
| 382 | if funcname[0] < 65 || funcname[0] > 90 { | ||
| 383 | panic("GoToFunc should exported function") | ||
| 384 | } | ||
| 385 | c.gotofunc = funcname | ||
| 386 | } | ... | ... |
| ... | @@ -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) |
| 404 | method = vc.MethodByName("Options") | 404 | method = vc.MethodByName("Options") |
| 405 | method.Call(in) | 405 | method.Call(in) |
| 406 | } | 406 | } |
| 407 | gotofunc := vc.Elem().FieldByName("gotofunc").String() | ||
| 408 | if gotofunc != "" { | ||
| 409 | method = vc.MethodByName(gotofunc) | ||
| 410 | if method.IsValid() { | ||
| 411 | method.Call(in) | ||
| 412 | } else { | ||
| 413 | panic("gotofunc is exists:" + gotofunc) | ||
| 414 | } | ||
| 415 | } | ||
| 407 | if !w.started { | 416 | if !w.started { |
| 408 | if AutoRender { | 417 | if AutoRender { |
| 409 | method = vc.MethodByName("Render") | 418 | method = vc.MethodByName("Render") | ... | ... |
-
Please register or sign in to post a comment