How to do it...

  1. Install the github.com/gorilla/mux package, using the go get command, as follows:
$ go get github.com/gorilla/mux
  1. Create http-rest-delete.go where we will define a route that supports the HTTP DELETE method and a handler that deletes the employee details for the provided ID from the static array of employees, marshals the array to JSON, and writes it to an HTTP response stream, as follows:
package mainimport (  "encoding/json"  "log"  "net/http"  "github.com/gorilla/mux")const (  CONN_HOST = "localhost"  CONN_PORT = "8080")type Route struct {  Name string  Method string  Pattern string  HandlerFunc http.HandlerFunc}type Routes []Routevar routes = Routes{  Route  {    "getEmployees",    "GET",    "/employees",    getEmployees,  },  Route  { "addEmployee", ...

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.