How to do it...

  1. Install the github.com/auth0/go-jwt-middleware, 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/auth0/go-jwt-middleware$ go get github.com/dgrijalva/jwt-go$ go get github.com/gorilla/handlers$ go get github.com/gorilla/mux
  1. Create http-rest-api-secured.go, where we will define the JWT middleware to check for JWTs on HTTP requests, and wrap the /employees route with it, as follows:
package mainimport (  "encoding/json"  "log"  "net/http"  "os"  "time"  jwtmiddleware "github.com/auth0/go-jwt-middleware"  jwt "github.com/dgrijalva/jwt-go"  "github.com/gorilla/handlers"  "github.com/gorilla/mux")const (  CONN_HOST = "localhost" CONN_PORT ...

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.