A few tips from Beego

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Beego frame Good, personal comparison like, the key is also some development tools are very practical, packaged a lot of implementation, do not need to do a lot of work, without considering the premise of efficiency, are acceptable categories.

Custom error page

The Beego default itself with some error pages, which are defined in the Error.go file. Take 404 as an example:

// Show 404 NotFound Error.func NotFound(RW http.Responsewriter, R *http.Request) {    T, _ := Template.New("Beegoerrortemp").Parse(ERRTPL)    Data :=  Make(Map[string]Interface{})    Data["Title"] = "Page not Found"    Data["Content"] = Template.HTML("<br>the page you had requested has flown the coop." +        "<br>perhaps You is here because:" +        "<br><br><ul>" +        "<br>the page has moved" +        "<br>the page no longer exists" +        "<br>you were looking for your puppy and got lost" +        "<br>you like 404 Pages" +        "</ul>")    Data["Beegoversion"] = VERSION    //RW.Writeheader(http.Statusnotfound)    T.Execute(RW, Data)}

In fact, it's easy to make a change yourself:

func Page_not_found(RW http.Responsewriter, R *http.Request){    T,_:= Template.New("404.html").Parsefiles(Beego.Viewspath+"/404.html")    Data := Make(Map[string]Interface{})    Data["Content"] = "Page not Found"    T.Execute(RW, Data)}func Main() {    Beego.ErrorHandler("404",Page_not_found)    Beego.Router("/", &Controllers.Maincontroller{})    Beego.Run()}

Modification of the Server field

The server in the HTTP return header always shows Beegoserver, which is too unprofessional to be defined in the Config.go file:

BeegoServerName = "beegoServer"

I originally fork a repo change, and later found that only need to define in the app.conf file can be:

BeegoServerName = ACGSOSERVER

This changes the server field so that other properties can be defined in this way.

golang beego
  • like
  • Tweet
  • +1
"!--/.social-share-->

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.