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

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