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. Install the github.com/astaxie/beego/context package using the go get command, as follows: 
$ go get github.com/astaxie/beego/context
  1. Move to $GOPATH/src/my-first-beego-project/filters and create firstfilter.go, which runs before the Controller, and log the IP address and current timestamp, as follows:
package filters import (  "fmt"  "time"  "github.com/astaxie/beego/context")var LogManager = func(ctx *context.Context) {   fmt.Println("IP :: " + ctx.Request.RemoteAddr + ",   Time :: " + time.Now().Format(time.RFC850))}
  1. Move to $GOPATH/src/my-first-beego-project/routers and edit router.go to add the GET mapping /*, which will be handled by the LogManager filter, as follows:
package routers import ( "my-first-beego-project/controllers" ...

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