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" ...

Get Go Web Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.