Move to $GOPATH/src/my-first-beego-project/views and create dashboard.tpl and copy the following content:
<!DOCTYPE html> <html> <body> <table border= "1" style="width:100%;"> {{range .employees}} <tr> <td>{{.Id}}</td> <td>{{.FirstName}}</td> <td>{{.LastName}}</td> </tr> {{end}} </table> </body> </html>
Move to $GOPATH/src/my-first-beego-project/controllers and edit firstcontroller.go to add the Dashboard handler, as follows:
package controllers import "github.com/astaxie/beego" type FirstController struct { beego.Controller } type Employee struct { Id int `json:"id"` FirstName string `json:"firstName"` LastName string `json:"lastName"` } type Employees []Employee var employees []Employee func init() { employees = Employees { Employee{Id: 1, FirstName: "Foo", LastName: "Bar"}, Employee{Id: 2, FirstName: "Baz", LastName: "Qux"}, } } ... func (this *FirstController) Dashbaord() { this.Data["employees"] = employees this.TplName = "dashboard.tpl" }
Move to $GOPATH/src/my-first-beego-project/routers and edit router.go to add the GET mapping /dashboard , which will be handled by the Dashboard handler defined in FirstController , as follows:
package routers import ( "my-first-beego-project/controllers" "github.com/astaxie/beego" ) func init() { beego.Router("/", &controllers.MainController{}) beego.Router("/employees", &controllers.FirstController{}, "get:GetEmployees") beego.Router("/dashboard", &controllers.FirstController{}, "get:Dashbaord") }
Run the project using the following command:
$ bee run
..................Content has been hidden....................
You can't read the all page of ebook, please click
here login for view all page.