4d06fec5 by astaxie

Merge pull request #55 from Unknwon/master

sync qucikstart.md to ZH version.
2 parents ea36f804 0e916a00
...@@ -472,7 +472,58 @@ You can use following to redirect: ...@@ -472,7 +472,58 @@ You can use following to redirect:
472 this.Redirect("/", 302) 472 this.Redirect("/", 302)
473 } 473 }
474 474
475 @todo Error processing need to be improved. 475 You can also throw an exception in your controller as follows:
476
477 func (this *MainController) Get() {
478 this.Abort("401")
479 v := this.GetSession("asta")
480 if v == nil {
481 this.SetSession("asta", int(1))
482 this.Data["Email"] = 0
483 } else {
484 this.SetSession("asta", v.(int)+1)
485 this.Data["Email"] = v.(int)
486 }
487 this.TplNames = "index.tpl"
488 }
489
490 Then Beego will not execute rest code of the function body when you call `this.Abort("401")`, and gives following default page view to users:
491
492 ![](images/401.png)
493
494 Beego supports following error code: 404, 401, 403, 500 and 503, you can customize your error handle, for example, use following code to replace 404 error handle process:
495
496 func page_not_found(rw http.ResponseWriter, r *http.Request){
497 t,_:= template.New("beegoerrortemp").ParseFiles(beego.ViewsPath+"/404.html")
498 data :=make(map[string]interface{})
499 data["content"] = "page not found"
500 t.Execute(rw, data)
501 }
502
503 func main() {
504 beego.Errorhandler("404",page_not_found)
505 beego.Router("/", &controllers.MainController{})
506 beego.Run()
507 }
508
509 You may be able to use your own `404.html` for your 404 error.
510
511 Beego also gives you ability to modify error message that shows on the error page, the following example shows how to set more meaningful error message when database has problems:
512
513 func dbError(rw http.ResponseWriter, r *http.Request){
514 t,_:= template.New("beegoerrortemp").ParseFiles(beego.ViewsPath+"/dberror.html")
515 data :=make(map[string]interface{})
516 data["content"] = "database is now down"
517 t.Execute(rw, data)
518 }
519
520 func main() {
521 beego.Errorhandler("dbError",dbError)
522 beego.Router("/", &controllers.MainController{})
523 beego.Run()
524 }
525
526 After you registered this customized error, you can use `this.Abort("dbError")` for any database error in your applications.
476 527
477 ##Handle response 528 ##Handle response
478 There are some situations that you may have in response: 529 There are some situations that you may have in response:
...@@ -889,6 +940,10 @@ Beego has many configurable arguments, let me introduce to you all of them, so y ...@@ -889,6 +940,10 @@ Beego has many configurable arguments, let me introduce to you all of them, so y
889 940
890 Maximum memory size for file upload, default is `1 << 26`(64M). 941 Maximum memory size for file upload, default is `1 << 26`(64M).
891 942
943 * EnableGzip
944
945 This value indicate whether enable gzip or not, default is false.
946
892 ##Integrated third-party applications 947 ##Integrated third-party applications
893 Beego supports to integrate third-party application, you can customized `http.Handler` as follows: 948 Beego supports to integrate third-party application, you can customized `http.Handler` as follows:
894 949
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!