O'Reilly logo

Go Web Development Cookbook by Arpit Aggarwal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it…

  1. Move to $GOPATH/src/my-first-beego-project/controllers and create errorcontroller.go, where we will define handlers to handle 404 and 500 HTTP errors as well as the handler to handle any generic error in an application, as follows:
package controllersimport "github.com/astaxie/beego"type ErrorController struct {  beego.Controller}func (c *ErrorController) Error404() {  c.Data["content"] = "Page Not Found"  c.TplName = "404.tpl"}func (c *ErrorController) Error500() {  c.Data["content"] = "Internal Server Error"  c.TplName = "500.tpl"}func (c *ErrorController) ErrorGeneric() {  c.Data["content"] = "Some Error Occurred"  c.TplName = "genericerror.tpl"}
  1. Move to $GOPATH/src/my-first-beego-project/controllers and edit firstcontroller.go ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required