How to do it...

  1. Install the github.com/astaxie/beego/session/redis package using the go get command, as follows:
$ go get -u github.com/astaxie/beego/session/redis
  1. Move to $GOPATH/src/my-first-beego-project/controllers and create sessioncontroller.go, where we will define handlers which make sure that only authenticated users can view the home page, as follows:
package controllers import "github.com/astaxie/beego"type SessionController struct {  beego.Controller}func (this *SessionController) Home() {  isAuthenticated := this.GetSession("authenticated")  if isAuthenticated == nil || isAuthenticated == false   {    this.Ctx.WriteString("You are unauthorized to     view the page.")    return  }  this.Ctx.ResponseWriter.WriteHeader(200) this.Ctx.WriteString("Home ...

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.