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/dgrijalva/jwt-go, github.com/gorilla/mux and github.com/gorilla/handlers packages using the go get command, as follows:
$ go get github.com/dgrijalva/jwt-go$ go get github.com/gorilla/handlers$ go get github.com/gorilla/mux
  1. Create create-jwt.go, where we will define the getToken handler that generates JWT, as follows:
package mainimport (  "encoding/json"  "log"  "net/http"  "os"  "time"  jwt "github.com/dgrijalva/jwt-go"  "github.com/gorilla/handlers"  "github.com/gorilla/mux")const (  CONN_HOST = "localhost"  CONN_PORT = "8080"  CLAIM_ISSUER = "Packt"  CLAIM_EXPIRY_IN_HOURS = 24)type Employee struct {  Id int `json:"id"`  FirstName string `json:"firstName"`  LastName string `json:"lastName"`}type Employees []Employee ...

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