How to do it...

  1. Install the github.com/gorilla/mux and github.com/gorilla/handlers packages using the go get command, as follows:
$ go get github.com/gorilla/mux$ go get github.com/gorilla/handlers
  1. Create http-rest-api.go, where we will define three routes—/status, /get-token and /employees—along with their handlers, as follows:
package mainimport (  "encoding/json"  "log"  "net/http"  "os"  "github.com/gorilla/handlers"  "github.com/gorilla/mux")const (  CONN_HOST = "localhost"  CONN_PORT = "8080")type Employee struct {  Id int `json:"id"`  FirstName string `json:"firstName"`  LastName string `json:"lastName"`}type Employees []Employeevar employees []Employeefunc init() {  employees = Employees  { Employee{Id: 1, FirstName: "Foo", LastName: "Bar"}, ...

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.