- Install the github.com/astaxie/beego/context package using the go get command, as follows:
$ go get github.com/astaxie/beego/context
- 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))}
- 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" ...